Reputation: 555
I programmed a UITextField to be rounded on the top left and right corners but the background of the textfield is now all black
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
How do I make it so the top left/right corners are the same radius but the textfield is fully visible?
Upvotes: 1
Views: 3475
Reputation: 72825
You're setting the layer's background color to black:
self.userEmailTextField.layer.backgroundColor = UIColor.black.cgColor
Try UIColor.clear.cgColor
instead, and you may want to set that after you draw the mask:
self.userEmailTextField.layer.mask = rectShape
self.userEmailTextField.layer.backgroundColor = UIColor.clear.cgColor
Upvotes: 3