Text inset for UITextField?

RunLoop picture RunLoop · Apr 22, 2010 · Viewed 203.3k times · Source

I would like to inset the text of a UITextField.

Is this possible?

Answer

azdev picture azdev · Oct 19, 2010

Overriding -textRectForBounds: will only change the inset of the placeholder text. To change the inset of the editable text, you need to also override -editingRectForBounds:

// placeholder position
- (CGRect)textRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 10);
}

// text position
- (CGRect)editingRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 10);
}