I have a simple rounded rect
override func draw(_ rect: CGRect) {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: cornerSize, height: cornerSize))
fillColor.setFill()
path.fill()
//fillColor is set to UIColor.black
//cornerSize is set to 20
}
But the corners are white. If I set background color in UIBuilder to clear color, the rounded rect becomes a rect with sharp corners. I tried to create an oval with rect and fill it with clear color. This also didn't work. Maybe the answer is trivial but I'm absolutely clueless.
Your code works fine as it is. If it is drawing solid black when the views background color is clear then that probably means you have a black view of the same size behind your bezier view. You can test this by changing the fill color of your bezier curve to something other than black.
Its a lot easier to debug if you use the @IBDesignable and @IBInspectable keywords:
@IBDesignable class BezierView: UIView {
@IBInspectable var fillColor = UIColor.black
@IBInspectable var cornerRadius = 20.0
override func draw(_ rect: CGRect) {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
fillColor.setFill()
path.fill()
}
}
It will then draw the view in the storyboard and you can edit the fill color and corner radius in the views inspector.