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!
推荐答案
从本质上讲,你需要设置按钮的文本字段控制(多行和将wordWrap),你不能没有扩展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屋!