iosswiftmathcore-graphicscgpath

Draw iOS 7-style squircle programmatically


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.


Solution

  • in iOS 13/ Xcode 11 you can now use CALayerCornerCurve

    Example

    yourLayer.cornerCurve = CALayerCornerCurve.continuous
    

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