像这样。
闭关修行中......
There is more than one method, you can use category, you can directly deceive users, you can...here is a kind of inheritance, the steps are as follows: 1) Inherit UITextfield 2) Rewrite - (void)drawRect:(CGRect)rect in the subclass as follows
- (void)drawRect:(CGRect)rect
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); CGContextFillRect(context, CGRectMake(0, CGRectGetHeight(self.frame) - 0.5, CGRectGetWidth(self.frame), 0.5)); }
3)TestCode is as follows:
#import "CustomField.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CustomField *textField = [CustomField new]; textField.frame = CGRectMake(0, 200, 100, 30); textField.backgroundColor = [UIColor yellowColor]; [self.view addSubview:textField]; }
4) Rendering:
There is more than one method, you can use category, you can directly deceive users, you can...here is a kind of inheritance, the steps are as follows:
1) Inherit UITextfield
2) Rewrite
- (void)drawRect:(CGRect)rect
in the subclass as follows3)TestCode is as follows:
4) Rendering: