简体   繁体   English

如何更改spark.components.Button的paddingLeft和paddingRight?

[英]How to change paddingLeft and paddingRight of spark.components.Button?

The class 'Button' in package mx.controls has the style 'paddingLeft' and 'paddingRight'. 包mx.controls中的类'Button'具有样式'paddingLeft'和'paddingRight'。 But now I don't want to use this old Halo theme anymore, I'm moving everything to Spark. 但是现在我不想再使用这个旧的Halo主题了,我将所有内容都移到了Spark上。

However, I can't find these padding styles in spark.components.Button, and the documentation http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/Button.html doesn't show that spark Button has those styles. 但是,我在spark.components.Button中找不到这些填充样式,而文档http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/spark/components/Button.html却找不到表明spark Button具有这些样式。

Any ideas? 有任何想法吗?

您必须做一个特定的按钮外观来继承默认按钮外观,并在其中添加规则。

It's actually pretty simple. 实际上很简单。 I'm pretty new to flex and (without doing anything else) after reading this post: 在阅读了这篇文章之后,我对flex和(不做其他任何事情)很陌生:

http://inflagrantedelicto.memoryspiral.com/2010/01/skinning-a-spark-button-in-flex-4/ http://inflagrantedelicto.memoryspiral.com/2010/01/skinning-a-spark-button-in-flex-4/

I created a spark button with custom left and right padding in less than a minute. 我在不到一分钟的时间内创建了一个带有自定义左右填充的火花按钮。 Thanks to Joseph Labrecque for his wonderful blog! 感谢Joseph Labrecque的精彩博客!

All you have to do in Flash Builder is right-click on the folder you want to create a new button skin inside of, then select New MXML Skin. 在Flash Builder中,您要做的就是右键单击要在其中创建新按钮外观的文件夹,然后选择“新建MXML外观”。 This opens the window you see in described in the link above. 这将打开您在上面的链接中描述的窗口。 The Package name will already be filled in (you can change it if you didn't right-click on the right folder above). 包名称将已经填写(如果您未在上面的右文件夹上单击鼠标右键,则可以更改它)。 Enter a name (eg CustomButton in the blog) for the skin class. 输入外观类的名称(例如,博客中的CustomButton )。 For Host Component, select Browse, then select Button-Spark Components . 对于“主机组件”,选择“浏览”,然后选择“ Button-Spark Components The "create-a-copy-of" checkbox should be selected by default. 默认情况下,应选中“创建副本”复选框。 Then click Finish. 然后单击完成。

Now all you have to do is open the file (it should open by default after you create it), then modify layer 8's Label section. 现在,您要做的就是打开文件(创建后默认情况下应打开),然后修改第8层的“标签”部分。 For me, it was line 219. Change left="10" to whatever placement you want (eg set to 0 for no padding). 对我来说,这是第219行。将left="10"更改为所需的任何位置(例如,设置为0表示无填充)。 Similar for right="10" . right="10"类似。 You can change the textAlign, and introduce paddingLeft or paddingRight , etc. inside the same label. 您可以更改textAlign,并在同一标签内引入paddingLeftpaddingRight等。 Save file when finished. 完成后保存文件。

Then inside your spark button mxml reference in your main file, simply add a skinclass="CustomButton" to the line of code. 然后在主文件中的火花按钮mxml引用内,只需在代码行中添加skinclass="CustomButton" For example, change this: 例如,更改此:

<s:button label="myOldButton" ... />

to this: 对此:

<s:button label="myCustomButton" skinclass="CustomButton" ... /> 

That's it! 而已!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM