[英]How do I remove the black border of a textfield?
I made a textfield in IB with the following settings: 我在IB中使用以下设置创建了文本字段:
The result is that the inside of the field is 15%, but there's a very thin visible border that isn't, and I want that removed. 结果是该字段的内部为15%,但是有一个非常细的可见边框不是,我希望将其删除。 I've tried doing it in code like this:
我试过在这样的代码中这样做:
textField.borderStyle = UITextBorderStyle.None
textField.layer.cornerRadius = 10
textField.layer.borderColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:0.15).CGColor
But this just puts the border on the inside covering the actual textfield. 但这只是将边框放在内部,覆盖了实际的文本字段。
Textfield: 文本域:
Try to add this: 尝试添加以下内容:
textField.layer.borderWidth = 0
Additionally, from the screenshot, it seems that textField.layer.cornerRadius = 10
is ignored, make sure that your textField
property is connected to the actual UITextField
. 此外,从屏幕快照中,似乎
textField.layer.cornerRadius = 10
被忽略了,请确保您的textField
属性已连接到实际的UITextField
。
The simplest approach to achieving a border-free textfield is to change the style of the textfield. 实现无边界文本字段的最简单方法是更改文本字段的样式。
Example Code 范例程式码
// Reference
@IBOutlet var tf: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Email TextField: no border
tf.borderStyle = .none
}
The Result 结果
Swift3 Swift3
passwordTF.layer.borderColor = UIColor.clear.cgColor
For me its working as well as 对我来说,它的工作以及
mobileNumberTF.borderStyle = .none
Try this one 试试这个
self.nameTextField.borderStyle = UITextBorderStyleNone; self.nameTextField.borderStyle = UITextBorderStyleNone;
I've tried several ways to remove the broder by programmatically and other suggested ways but later figured out this is the only way it removes the border from UITextField. 我尝试了几种方法,以编程方式和其他建议的方式删除了broder,但后来发现这是从UITextField删除边框的唯一方法。 Just select in interface builder, Border Style option
只需在界面生成器中选择“边框样式”选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.