Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smooth rounded corners in swift

Tags:

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?

like image 891
WalterBeiter Avatar asked Sep 13 '18 09:09

WalterBeiter


People also ask

How can we create an iOS like rounded shape with smooth corners?

Click the icon to adjust each individual corner. Click to open the Corner Smoothing setting. Drag the slider right to increase and left to decrease. Click iOS to set Corner Smoothing to 60%, the default for iOS.

What is corner radius in iOS?

Discussion. Setting the radius to a value greater than 0. 0 causes the layer to begin drawing rounded corners on its background. By default, the corner radius does not apply to the image in the layer's contents property; it applies only to the background color and border of the layer.


1 Answers

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

like image 180
Vincent Friedrich Avatar answered Oct 09 '22 22:10

Vincent Friedrich