从UITextField类继承一个类
.h文件
1 @interface CustomTextField : UITextField2 3 @end
.m文件
1 #import "CustomTextField.h" 2 3 @implementation CustomTextField 4 5 - (CGRect)textRectForBounds:(CGRect)bounds{ 6 return CGRectInset(bounds, 5, 0); 7 } 8 9 - (CGRect)editingRectForBounds:(CGRect)bounds{10 return CGRectInset(bounds, 5, 0); 11 }12 13 - (void)drawRect:(CGRect)rect{14 //[super drawRect:rect];15 UIImage *bg = [[UIImage imageNamed:@"text_field_teal.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 5, 15, 5)];16 [bg drawInRect:[self bounds]];17 }18 19 @end