开发者

UITextField input text position [duplicate]

This question a开发者_运维问答lready has answers here: Set padding for UITextField with UITextBorderStyleNone (32 answers) Closed 10 years ago.

Hello I'm making a custom UITextField like so :

_textField.borderStyle=UITextBorderStyleNone;
_textField.backgroundColor = _color;
_textField.layer.borderColor = [[UIColor grayColor]CGColor];
_textField.layer.borderWidth = 1.0f;
_textField.layer.cornerRadius = 8.0f;
_textField.font = [UIFont systemFontOfSize:14];

The result I get is (image url) http://img402.imageshack.us/img402/4330/questionyd.jpg

Question : How do I move the input text slightly to the right so it doesn't touch the border ? I suppose I must define some .frame property but can't figure which one.

thanks ! Louis


You can set the leftView property with an empty UIView and a small frame, set the leftViewMode property to UITextFieldViewModeAlways, so your placeholder view is always used.

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
_textField.leftView = view;
_textField.leftViewMode = UITextFieldViewModeAlways;
[view release];


You may try creating your own subclass of UITextField and override the method:

-(CGRect)textRectForBounds:(CGRect)bounds

Set your own bounds rather then deal with the default.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜