UITextField input text position [duplicate]

拟墨画扇 提交于 2019-12-05 06:33:33

问题


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


回答1:


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];



回答2:


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.



来源:https://stackoverflow.com/questions/5722918/uitextfield-input-text-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!