How to draw shapes with CAShapeLayer

CAShapeLayer is one of the most useful CALayer subclasses. It uses hardware-accelerated drawing to create and draw a all manner of 2D shapes.  Also, it includes extra features such as fill, patterns, strokes and line caps and more.

The below example will draw a rounded rectangle, which we will color green.

Since Xcode 6 we’ve been given the ability to see the changes live within storyboard/interface builder.

Add the following class to your project

Then over in storyboard add a UIView and change the class to DrawingShape

Then finally pop over to attribute inspector to see the properties you’ve just created.