Rounded corners on a UIView

Every UIView object has a layer property that can be used to apply shadows, rounded corners, and other interesting effects to your views. Today i needed to be able to set rounded corners independently of each other.

After perusing the CALayer documentation it looked as if you could only use the cornerRadius property if you wanted to set ALL the corners to a specific radius. What i failed to remember was that i had solved a similar issue earlier when needing to apply a shadow to a UIView with rounded corners. The solution of this ended up leading me to use a CGPath object to define where the shadow should be.

A few more minutes on the interwebs and it seemed i could define a views bounds by using a path as well. Not only that but there is a handle little method for created a path with rounded corners individually! Check it out!

You can adjust which corners you want to round or not round by adjusting the byRoundingCorners method parameter.

Happy Rounding.