自定义UITextField

从UITextField类继承一个类

.h文件

1 @interface CustomTextField : UITextField
2 
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

 

posted @ 2013-02-18 15:36  diablo大王  阅读(1313)  评论(0编辑  收藏  举报