我编写了一个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
如何制作左上/右上角的半径相同但文字区域完全可见?
答案 0 :(得分:2)
您将图层的背景颜色设置为黑色:
self.userEmailTextField.layer.backgroundColor = UIColor.black.cgColor
请尝试使用UIColor.clear.cgColor
,您可能需要在之后设置以绘制遮罩:
self.userEmailTextField.layer.mask = rectShape
self.userEmailTextField.layer.backgroundColor = UIColor.clear.cgColor