One of the changes in iOS 7 is that it favors the use of circular image over square image. You can find circular icons or images in stock apps such as Contacts and Phone. In this short post, we’ll explore the CALayer class and see how you can apply it to create circular image or image with rounded corner.
You may not heard of the CALayer class. But you should have used it in some ways if you’ve built an app. Every view in the UIKit (e.g. UIView, UIImageView) is backed by an instance of the CALayer class (i.e. layer object). The layer object is designed to manage the backing store for the view and handles view-related animations.
The layer object provides various attributes that can be set to control the visual content of the view such as:
- Background color
- Border and border width
- Shadow color, width, etc
- Corner radius
The corner radius is the attribute that we’ll use to draw rounded corner and circular image.
As always, the best way to understand how CALayer works is to use it. We’ll create a simple profile view with a circular profile photo.