如何只留下UITextField的下边框?

时间:2018-06-08 11:17:43

标签: ios swift uitextfield

必须只在UITextField留下底部边框。出于某种原因,我的代码不起作用。

let bottomLine = CALayer()
bottomLine.frame = CGRect(x:0.0, y:1.0, width: myTextField.frame.width, 
height: myTextField.frame.height - 1)
bottomLine.backgroundColor = UIColor.white.cgColor
myTextField.borderStyle = UITextBorderStyle.None
myTextField.layer.addSublayer(bottomLine)

2 个答案:

答案 0 :(得分:0)

替换此

 bottomLine.frame = CGRect(x:0.0, y:1.0, width: myTextField.frame.width,height: myTextField.frame.height - 1)

bottomLine.frame = CGRect(x:0.0, y:myTextField.frame.height - 1, width: myTextField.frame.width,height: 1)

答案 1 :(得分:0)

在我的案例中添加:

myTextFeld.wantsLayer = true