I have drawn a rounded rectangle with corner radius by UIBezierPath with init(roundedRect:byRoundingCorners:cornerRadii:)
But I found that when corner radius is more than about 33% of the rectangle's width or height then corner radius are drawn by 50% of rectangle's width or height.
Is this an iOS bug or Did I just do something wrong?
I just want the corner radius is the same with the value when the corner radius is less than 50% of the rectangle's width or height.
Example Code
final class CornerView: UIView {
override func draw(_ rect: CGRect) {
let rect = CGRect(x: 100, y: 100, width: 100, height: 100)
let roundedPath0 = UIBezierPath(
roundedRect: rect,
byRoundingCorners: [.allCorners],
cornerRadii: CGSize(width: 20, height: 20))
UIColor.black.setFill()
roundedPath0.fill()
let roundedPath1 = UIBezierPath(
roundedRect: rect,
byRoundingCorners: [.allCorners],
cornerRadii: CGSize(width: 25, height: 25))
UIColor.green.setFill()
roundedPath1.fill()
let roundedPath2 = UIBezierPath(
roundedRect: rect,
byRoundingCorners: [.allCorners],
cornerRadii: CGSize(width: 30, height: 30))
UIColor.blue.setFill()
roundedPath2.fill()
let roundedPath3 = UIBezierPath(
roundedRect: rect,
byRoundingCorners: [.allCorners],
cornerRadii: CGSize(width: 35, height: 35))
UIColor.red.setFill()
roundedPath3.fill()
}
}
Result
The red rectangle should be drawn in the same corner radius ratio with the below rectangles.
I'm using
Xcode Version 13.4.1 (13F100)
iOS Simulator: iOS 15.5 iPhone 8 Plus