smooth rounded corners in swift
Starting iOS 13.0, you can just use this property in addition to setting the cornerRadius:
sampleButton.layer.cornerCurve = .continuous
This is also easily animatable, which previously resulted in problems using a UIBezierPath.
See more at https://developer.apple.com/documentation/quartzcore/calayer/3152596-cornercurve
Prior to iOS 13
To get that effect you can use UIBezierPath
Edit: Usage in UIView
class MyView: UIView {
let myButton UIButton = UIButton()
override func layoutSubviews() {
super.layoutSubviews()
// your roundPath code here
}
}
Edit 2:
Use this approach for rounding specific corners:
let roundPath = UIBezierPath(
roundedRect: bounds,
byRoundingCorners: [.topLeft, .topRight],
cornerRadii: CGSize(width: 10, height: 10)
)
Source