很多时候系统默认的UITextField不够我们的需求,所以需要自定义
其实也很简单
头文件
#import <UIKit/UIKit.h>
@interface mCustomTextField : UITextField
@end
源文件
#import "mCustomTextField.h"
@implementation mCustomTextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(CGRect)textRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds, 5, 0);
}
-(CGRect)editingRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds,5,0);
}
-( void )drawRect:(CGRect)rect
{
UIImage * backgroundImage = [[UIImage imageNamed:@ "text_field_teal.png" ] resizableImageWithCapInsets:UIEdgeInsetsMake(15.0, 5.0, 15.0, 5.0)];
[backgroundImage drawInRect:[self bounds]];
}
@end