@IBDesignable and @IBInspectable

Posted by on November 22, 2016

A lot has been written about the @IBInspectable and @IBDesignable properties, but it’s not that easy to find a simple example on how to use them on Swift.

@IBInspectable is a property that you can assign to your custom UIViews variables in order to get a fancy way of assigning values via Interface Bulder. Every variable that has this prefix would appear on the storyboard as far as it uses one of the acceptable run time classes. These are String, Boolean, Numbers, CGSize, CGRect, CGPoint, UIColor UIIMage and NSRange.

Screen Shot 2016-11-22 at 16.39.13

@IBInspectable tells Xcode to compile our view when it’s used on the storyboard, so we can see the changes in real time.

Here we’ve a very simple example on how to do it with a UIView and assign corner radius, border width and color. I’m putting it here because I wasn’t able to find a good simple example on how to do it. Hope it can help you as a base to create your own more complex classes.




Posted in: Development


Be the first to comment.

Leave a reply

Simple Business by Nimbus Themes
Powered by WordPress