Adobe Flex:按钮标签中的自动换行 [英] Adobe Flex: Word Wrap in Button Label
问题描述
标准的 Flex 按钮不允许标签文本自动换行.我在互联网上读到有一些未公开的方法来处理这个问题,但我没有让它们起作用.如果有人能给我发一个小例子就太好了!
The standard Flex button does not allow the Label Text to word wrap. I read in the internet that there are some undocumented ways to handle this but I did not get them to work. If somebody could post me a small example would be great!
推荐答案
本质上,您需要在 Button 的 TextField 控件(multiLine 和 wordWrap)上设置一些受保护的属性,如果不扩展 Button 类就无法做到这一点.因此,如果您创建一个新类来扩展 Button 并设置这些属性,并做一些工作以正确测量:
Essentially you need to set a few protected properties on the Button's TextField control (multiLine and wordWrap), which you can't do without extending the Button class. So if you create a new class that extends Button and sets those properties and does a little work to make things measure out correctly:
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 中:
... you can drop that control into your MXML like so:
<?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>
希望有帮助!如果您有问题,请回帖.
Hope it helps! Post back with questions if you have 'em.
这篇关于Adobe Flex:按钮标签中的自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!