Textfield Vertical Align

How do you align text in a textfield vertically? (For example, at the top of the field or in the middle.)

You have to set its y position relative to its parent.height.

For example:

var button: Sprite = new Sprite();
button.graphics.beginFill(0);
button.graphics.drawRoundRect(0, 0, 200, 50, 4, 4);
button.graphics.endFill();
button.x = button.y = 30;
addChild(button);

var label: TextField = new TextField();
label.text = "Hello World";
label.autoSize = TextFieldAutoSize.LEFT;
label.defaultTextFormat = new TextFormat("Arial", 12, 0xFFFFFF);
button.addChild(label);		
label.x = parent.width / 2 - label.width / 2;		
label.y = parent.height / 2 - label.height / 2;

image

1 Like