开发者

How can I do padding top and bottom of TextField in actionscript3?

开发者 https://www.devze.com 2023-04-02 13:47 出处:网络
Padding left can be done by TextFormat.leftMargin. And padding right can be done by TextForm开发者_C百科at.rightMargin.

Padding left can be done by TextFormat.leftMargin.

And padding right can be done by TextForm开发者_C百科at.rightMargin.

But there is no topMargin or bottomMargin property in TextField or TextFormat.

How can I do padding top and bottom?

Example code of left and right padding(margin) of TextField:

var format:TextFormat = new TextFormat
format.leftMargin = 40
format.rightMargin = 40

var text:TextField = new TextField
text.defaultTextFormat = format
text.background = true
text.backgroundColor = 0xeeaaaa
text.autoSize = TextFieldAutoSize.CENTER
text.text = 'abc'


Just increase the height of your sprite, text.height + 10 for example, and set text.y = 5 for a 5 pixel top and bottom margin


You can also add a blank line before and after your text. Combined with the border and background properties of a textField object you can render nice boxes. Code would look like this:

var text:TextField = new TextField
text.defaultTextFormat = format
text.background = true
text.backgroundColor = 0xeeaaaa
text.autoSize = TextFieldAutoSize.CENTER
text.text = '\n' + 'your text here' + '\n '

If you use this solution, do not forget the blank space after the second blank line. It makes sure the blank line is displayed.


I believe there's no native way to do it. Here is a list of supported CSS tags (it does not include any padding, nor top or bottom margin): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StyleSheet.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6


There is no predefined option available right now.

But you can text.y property instead of top margin and bottom margin.

var format:TextFormat = new TextFormat;
format.leftMargin = 40;
format.rightMargin = 40;
var text:TextField = new TextField;
text.defaultTextFormat = format;
text.autoSize = TextFieldAutoSize.CENTER;
text.text = 'abc\ndef\nhij\nlmno';
var spr:Sprite = new Sprite();
spr.graphics.beginFill(0xeeaaaa,1);
spr.graphics.drawRect(0,0, text.width,text.height);
spr.graphics.endFill();
addChild(spr);
spr.addChild(text);
0

精彩评论

暂无评论...
验证码 换一张
取 消