我编写了一个 UITextField 使其在左上角和右上角变圆,但文本字段的背景现在全黑了
let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
backgroundImage.image = UIImage(named: "signupbackground.jpg")
self.view.insertSubview(backgroundImage, at: 0)
self.signupButton.layer.cornerRadius = 5
let rectShape = CAShapeLayer()
rectShape.bounds = self.userEmailTextField.frame
rectShape.position = self.userEmailTextField.center
rectShape.path = UIBezierPath(roundedRect: self.userEmailTextField.bounds, byRoundingCorners: [.topLeft , .topRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
self.userEmailTextField.layer.backgroundColor = UIColor.black.cgColor
//Here I'm masking the textView's layer with rectShape layer
self.userEmailTextField.layer.mask = rectShape
如何使左上角/右上角的半径相同但文本字段完全可见?
最佳答案
您正在将图层的背景颜色设置为黑色:
self.userEmailTextField.layer.backgroundColor = UIColor.black.cgColor
请尝试使用 UIColor.clear.cgColor
,您可能希望在绘制 mask 后设置它:
self.userEmailTextField.layer.mask = rectShape
self.userEmailTextField.layer.backgroundColor = UIColor.clear.cgColor
关于ios - UITextField的透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39908455/