UITextField input text position [duplicate]
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.
精彩评论