我想自定义一个UITextField
iOS 6
它看起来像一个只有底部边框的透明文本字段。我在之前的计算器中发现了一个图像,但由于我没有10个声望,我无法发布图像,但我发布了下面的链接。是否有可能在iOS 6中创建只有底部边框的UITextField?
Text field with bottom border only in ios6
我想自定义一个UITextField
iOS 6
它看起来像一个只有底部边框的透明文本字段。我在之前的计算器中发现了一个图像,但由于我没有10个声望,我无法发布图像,但我发布了下面的链接。是否有可能在iOS 6中创建只有底部边框的UITextField?
Text field with bottom border only in ios6
有多种方式来实现:
创建seperatorView并将其添加子视图的UITextField与Y轴为文本框的高度。
UITextfield *namefield = [[UITextfield alloc] initwithframe:CGRectMake(20,40,70,40) ];
UIView *seperator=[UIView new];
seperator.backgroundColor = [UIColor grayColor];
seperator.frame =CGRectMake(namefield.frame.origin.x, namefield frame.origin.y+namefield.frame.size.height-1, namefield.frame.size.width,1);
[namefield addSubView:seperator];
通过使用CoreAnimation类
CALayer *bottomBorder = [CALayer layer];
CGFloat borderWidth = 1;
bottomBorder.borderColor = [UIColor grayColor].CGColor;
bottomBorder.frame = CGRectMake(0, textField.frame.size.height - borderWidth, textField.frame.size.width, textField.frame.size.height);
bottomBorder.borderWidth = borderWidth;
[textField.layer addSublayer:border];
textField.layer.masksToBounds = YES;
通过创建的UITextField和压倒一切的drawRect方法的自定义类。
使用图像并将其作为backgroundColor添加到UITextfield。
感谢队友......第二个人为我工作,但我做了必须将边框宽度增加到8.0f,否则无法看到。 @Arun Gupta –
当然...那些你可以相应地自定义样例代码的地方.. –
为什么你想要支持iOS 6? iOS 9将在几个月后出来。 – rmaddy
我正在接受iOS应用程序开发方面的培训,但我们这里的学生没有亲自在家里使用MAC Book,所以我们在VMWare中使用Mountain Lion OS,并且不支持XCODE 5,这就是为什么朋友。 @rmaddy –
这很遗憾,因为您正在使用过时的API学习过时的工具。很多改变了。该版本不能用于将应用程序发送给Apple。 – rmaddy