iOS Trick: Add padding to a UITextField
March 4, 2011
Subclass UITextField and override this function:
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectMake(bounds.origin.x + 10, bounds.origin.y + 8,
bounds.size.width - 20, bounds.size.height - 16);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [self textRectForBounds:bounds];
}
Good practice is have your own text field class with “paddingX” and “paddingY” properties.
Advertisement
No comments yet