本文介绍了如何删除文本框的黑色边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在IB中使用以下设置创建了一个文本字段:
I made a textfield in IB with the following settings:
- 边框样式:RoundRect
- View的BG颜色:黑色,不透明度:15%
结果是该字段的内部为15%,但是有一个非常细的可见边框不是,我希望将其删除.我已经尝试过在这样的代码中做到这一点:
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. 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.
文本字段:
推荐答案
Swift 3/Swift 4
实现无边界文本字段的最简单方法是更改文本字段的样式.
Swift 3 / Swift 4
The simplest approach to achieving a border-free textfield is to change the style of the textfield.
- 对文本字段进行IBOutlet引用.
- 设置文本字段的边框样式都没有.
- Make a IBOutlet reference to the textfield.
- Set the textfield'sborder style to none.
示例代码
// Reference
@IBOutlet var tf: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Email TextField: no border
tf.borderStyle = .none
}
结果
这篇关于如何删除文本框的黑色边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!