Adobe Flex:按钮标签中的自动换行

时间:2009-10-31 13:33:34

标签: flex button

标准Flex按钮不允许标签文本自动换行。我在互联网上读到,有一些无证的方法可以解决这个问题,但我没有让它们发挥作用。如果有人能给我发一个小例子会很棒!

2 个答案:

答案 0 :(得分:15)

基本上你需要在Button的TextField控件(multiLine和wordWrap)上设置一些受保护的属性,如果不扩展Button类就不能这样做。因此,如果您创建一个扩展Button的新类并设置这些属性,并做一些工作来使事情正确测量:

package
{
    import flash.text.TextFieldAutoSize;
    import mx.controls.Button;

    public class WrappingButton extends Button
    {


        public function WrappingButton()
        {
            super();
        }

        override protected function createChildren():void
        {
            super.createChildren();

            textField.multiline = true;
            textField.wordWrap = true;
            textField.autoSize = TextFieldAutoSize.CENTER;
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            textField.y = (this.height - textField.height) >> 1;

            height = textField.height + getStyle("paddingTop") + getStyle("paddingBottom");
        }
    }
}

...您可以将控件放入MXML中,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">

    <local:WrappingButton label="The quick brown fox jumped over the lazy dog." width="100" paddingTop="10" paddingBottom="10" />

</mx:Application>

希望它有所帮助!如果你有问题,请回复问题。

答案 1 :(得分:4)

尝试使用&#13;

我正在使用

<s:Button label="Top two&#13;states result" height="100%" width="100%" icon="@Embed(source='assets/bar.png')" chromeColor="#A3F4FD"/>

它有多行标签。

相关问题