Clicky

iOS Dev Nugget 227 View with Rounded Corners

.

Need to run a code review on your codebase? Hire me

Sometimes you want to make a subview have rounded corners. An easy way to do this is:

v.backgroundColor = bgColor
v.layer.cornerRadius = 7
v.layer.masksToBounds = true

This works well most of the time, but you run into performance degradation when you render more complex subviews with rounded corners, e.g many UILabels with rounded corners in a UITableView with many cells.

An easy way around this issue is to switch of masksToBounds and set the background on the layer instead of the view:

v.layer.backgroundColor = bgColor.cgColor
v.layer.cornerRadius = 7


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues