How to change the height of a TextField?
If I create a TextField
in ActionScript 3, I can change the width with a TextFormat
, but how do I change the height?
Example:
var label : TextField = new TextField();
label.text = "开发者_Go百科Hello World!";
label.background = true;
label.backgroundColor = 0x800000; // Red background to see TextField boundary
label.autoSize = "center";
var format : TextFormat = new TextFormat();
format.leftMargin = 20;
format.rightMargin = 20;
label.setTextFormat( format );
addChild( label );
// Setting the height explicitly doesn't work
label.height = label.width * 1.5;
autoSize is the problem:
label.autoSize = "center";
Removing autoSize setting allows you to change the height of textField. If you want to set the alignment, use setTextFormat instead.
setTextFormat
setTextFormat
will obviously set a TextFormat
, changing the appearance of your text, but it will not change the text field it is displayed in. If you want to change the width and height of your text field, use TextField.width
and TextField.height
.
You can combine those with TextField.autoSize
as well: If you set width
after autoSize
, the TextField will resize only vertically, while if you set height
after autoSize
, it will resize horizontally. You have to choose between one of those, of course.
If you want to automatically increase the height of a textfield, you need to set:
label.multiline = true;
label.wordWrap = true;
Wordwrap takes care of the end of the line within the width you set for your textfield.
精彩评论