I know there is a method to draw a roundedRect - UIBezierPath(roundedRect, cornerRadius)
But I would like to know if I clip the corner by myself, why should I have to addClip before draw a rectangle? (I feel like clip the rectangle after it was draw is more reasonable. What concept did I miss?)
(1) work
override func drawRect(rect: CGRect) {
var clipPath = UIBezierPath(roundedRect: rect, cornerRadius: 8.0)
path.addClip()
var rectPath = UIBezierPath(rect: rect)
UIColor.redColor().setFill()
rectPath.fill()
}
(2) not work
override func drawRect(rect: CGRect) {
var rectPath = UIBezierPath(rect: rect)
UIColor.redColor().setFill()
rectPath.fill()
var clipPath = UIBezierPath(roundedRect: rect, cornerRadius: 8.0)
path.addClip()
}
If you imagine the drawing area as a sheet of paper, clipping does not mean that you cut something off it with a scissor after drawing. Instead it is more like putting a stencil board on the sheet and only the punched-out areas are relevant for drawing then.
This concept gives you more flexibility, because you can remove or exchange the stencil board at any time, i.e. set a new clipping path, which can be very useful for more complex drawings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With