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

更新时间:2020-03-31    来源:文本特效    手机版     字体:

【www.bbyears.com--文本特效】

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

本文来源:http://www.bbyears.com/wangyetexiao/90958.html

热门标签

更多>>

本类排行