A better way of accessing properties of your view’s layer from Interface Builder

Interface Builder can make laying out complex UI a breeze. It saves a lot of time and is becoming even better and more powerful with every Xcode update. However, it is not that perfect (yet) and trivial tasks like rounding a view’s corners in IB may require doing something like this:

Yikes! Defining runtime attributes in IB is error-prone and kinda time consuming.

There is a better way of accessing the properties your view’s underlying CALayer in IB. All you have to do is to create an extension for UIView class with properties that proxy its layer’s properties and apply @IBInspectable attribute to each of those properties:

With this extension in place, you will notice that any view in IB will have a new set of attributes in Attribute inspector:

Ah, much better, isn’t it?

I hope this will make your experience with Interface Builder even more enjoyable. Happy coding! 🙂

Leave a Reply

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