图中这种输入框是怎么实现的
左边的小图标一定要使用镂空图,不然不会透过去。
右边是TextField,用 TextField.placeholder = @"用户名";
设置TextField无边框: TextField.backgroundColor = [UIColor clearColor];
下面的那条线可以建一个UIView: View的高度为0.5,就和一条线一样了。
能看懂吧哈~
可以用category,可以...这里说一种继承,步骤如下:
1)继承UITextfield
2)重写子类中的- (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 如下:
@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];
}
「用户名」和「密码」是两个TextField,设置了placeholder属性。
左边是两个icon,下方的白线可以自己画,可以贴图。
这种界面我比较喜欢用 Storyboard 来拖,基本不用写代码。
送lz篇教程:
http://www.raywenderlich.com/55384/ios-7-best-practices-part-1
2 回答1k 阅读
1 回答1.1k 阅读✓ 已解决
1 回答2.7k 阅读
1 回答1.5k 阅读
1 回答1.4k 阅读
1.7k 阅读
1 回答1.1k 阅读
这个可以使用UI控件来拼装的
效果