iOS开发技术

IOS自定义输入框(方便以后使用)

2016-08-03  本文已影响123人  lxf_2013

.h文件

#import <UIKit/UIKit.h>

@interface UITextFieldBottomLine : UITextField

- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;

@end

.m文件

//底部细线
- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
//颜色
    CGContextSetFillColorWithColor(context, [UIColor lightGrayColor].CGColor);
//范围
    CGContextFillRect(context, CGRectMake(0, CGRectGetHeight(self.frame) - 0.5, CGRectGetWidth(self.frame), 0.5));
}
//控制文本所在的的位置,左右缩 10
- (CGRect)textRectForBounds:(CGRect)bounds {
    return CGRectInset( bounds , 10 , 0 );
}

//控制编辑文本时所在的位置,左右缩 10
- (CGRect)editingRectForBounds:(CGRect)bounds {
    return CGRectInset( bounds , 10 , 0 );
    
}
上一篇下一篇

猜你喜欢

热点阅读