一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

flash中AS3 让TextField自适应内容高度(根据内容自动调整高度)

时间:2015-12-28 编辑:简简单单 来源:一聚教程网

时使用TextField文本框显示文字时,想让TextField能随内容自动调整高度,而不是设置个固定高度。如下图:

原文:AS3 - 让TextField自适应内容高度(根据内容自动调整高度)
 
实现方法:
在设置完 TextField 的文本内容后,将其高度设置为内容高度(textHeight)。同时由于文本内容区域距边框上下左右都有2像素边距,所有高度还要加4。
原文:AS3 - 让TextField自适应内容高度(根据内容自动调整高度)


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.;
            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);
        }
    }
}

热门栏目