Reputation: 21
Using UIBezierPath, I am attempting to create a yellow rounded rectangle "on top of" the gray background of the custom UIView. I'd appreciate if you could help me understand why this code snippet is not working:
class CardView: UIView {
override func draw(_ rect: CGRect) {
let roundedRect = UIBezierPath(roundedRect: bounds, cornerRadius: 16.0)
UIColor.yellow.setFill()
roundedRect.fill()
}
}
Thank you for your help!
Upvotes: 0
Views: 149
Reputation: 21
I figured it out . . . I did not call the addClip() method.
class CardView: UIView {
override func draw(_ rect: CGRect) {
let roundedRect = UIBezierPath(roundedRect: bounds, cornerRadius: 16.0)
roundedRect.addClip()
UIColor.yellow.setFill()
roundedRect.fill()
}
}
This now works.
Upvotes: 2