CAShapeLayer example – Round corners view with dashed line border

Drawing on a UIView is explained using a simple example of a view with round corners and a dashed line border. CGMutablePathRef is created and different kind of shapes are added like lines (CGPathAddLineToPoint) and arcs (CGPathAddArc). After you have drawn the path you wanted it is set as the CAShapeLayer object’s path. The CAShapeLayer object is added as a sublayer of a UIView. Now you have the graphics on the UIView. This way a border may be drawn around a UIView, as in this simple example.

To test this example you need to link the binary with CoreGraphics and QuartzCore libraries. Also you need to import QuartzCore (#import <QuartzCore/QuartzCore.h>).

You may download LBorderView lib that uses this code and a sample project from my git repo at: https://github.com/lukagabric/LBorderView

Related Post

Remember to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someone

2 thoughts on “CAShapeLayer example – Round corners view with dashed line border

Leave a Reply

Your email address will not be published. Required fields are marked *