ios - UItextfield怎么做成下划线样式的?输入的文本在下划线上面?
阿神
阿神 2017-04-17 13:54:51
0
1
615

像这样。

阿神
阿神

闭关修行中......

reply all(1)
小葫芦

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 {
    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:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template