Use Storyboard to mask UIView and give rounded corners?

Crashalot picture Crashalot · Dec 11, 2015 · Viewed 86.7k times · Source

Lots of questions like this explain how to programmatically create a mask and provide rounded corners to a UIView.

Is there a way to do it all within Storyboard? Just asking because it seems like creating rounded corners in Storyboard keeps a clearer demarcation between presentation and logic.

Answer

Woraphot Chokratanasombat picture Woraphot Chokratanasombat · Dec 11, 2015

Yes, I use that a lot but question like this was already answered many times.

But anyway in Interface Builder. You need to add User Defined Runtime Attributes like this:

layer.masksToBounds Boolean YES
layer.cornerRadius Number {View's Width/2}

enter image description here

and enable

Clips subviews

enter image description here

Results:

enter image description here