Ios – smooth rounded corners in swift

iosrounded-cornersswift

How can I create a UIButton with rounded corners that are smooth?
The standard apple rounded corners are much nicer than the standard rounded corners.
If I design a button in sketch, I can toggle "smooth corners" which toggles the corners of a shape from Apple rounded corners (smooth) to standard rounded corners.

Here is a comparison:

enter image description here

How can I toggle this in swift?

showContentButton.layer.cornerRadius = 20 rounds the corners, however, I don't really know if this rounded corners are "smooth corners" or "standard rounded corners". And I don't know how to toggle this. Any ideas?

Best Answer

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