【www.bbyears.com--文本特效】
时使用TextField文本框显示文字时,想让TextField能随内容自动调整高度,而不是设置个固定高度。如下图:
实现方法: 在设置完 TextField 的文本内容后,将其高度设置为内容高度(textHeight)。同时由于文本内容区域距边框上下左右都有2像素边距,所有高度还要加4。
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
public class Test111 extends Sprite
{
public function Test111()
{
super();
var textField:TextField = new TextField();
textField.defaultTextFormat = new TextFormat("Verdana", 10, 0xFFFFFF);
textField.background = true;
textField.backgroundColor = 0x2D9900;
textField.width = 100;
textField.x = 10;
textField.y = 10;
textField.text = "条目1\n条目2\n条目3\n条目4\n条目5\n条目6";
//由于文本内容区域距边框上下左右都有2像素边距,所有还要加4
textField.height = textField.textHeight + 4;
this.addChild(textField);
}
}
}