Draw iOS 7-style squircle programmatically

Remy Vanherweghem picture Remy Vanherweghem · Aug 22, 2013 · Viewed 7.8k times · Source

I'm trying to find a way to draw a iOS 7-style icon 'squircle' shape programmatically, using core graphics. I'm not asking how to draw a rounded rectangle. A squircle is a superellipse:

Squircle

which is slightly different than a regular rounded rectangle: Rounded rectangle vs squircle

Music icon in squircle

It's exact formula is readily available. However, I can't figure out how to draw this using, for example, a CGPath, let alone fill it, and be able to resize it rather easily. All this while being entirely exact with the formula.

Answer

Ted picture Ted · Jun 4, 2019

in iOS 13/ Xcode 11 you can now use CALayerCornerCurve

Example

yourLayer.cornerCurver = CALayerCornerCurve.continuous

source: https://developer.apple.com/documentation/quartzcore/calayercornercurve