1

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

Louis de Decker
  • 525
  • 1
  • 7
  • 14

2 Answers2

4

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];
etolstoy
  • 1,798
  • 21
  • 33
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
4

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.

etolstoy
  • 1,798
  • 21
  • 33
The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69