@IBInspectable & @IBDesignable

IBInspectable – provided new ways to old features like user defined runtime attribute are powerful way to configuring any Key-value coded property of an instance XIB. But its really hard to manage and if you have multiple views with same or may be different properties.

for example, these properties in UIView subclass update the backing layer with their values.

@IBInspectable var corberRadius : CGFloat = 0 {
        didSet {
            layer.cornerRadius = corberRadius
            layer.masksToBounds = corberRadius > 0
        }
    }

IBDesignable lets interface builder know it should render the view directly in the canvas. This will allow you to see how’s your view will appear without even building the application.

@IBDesignable
class BaseView: UIView {
    @IBInspectable var corberRadius : CGFloat = 0 {
        didSet {
            layer.cornerRadius = corberRadius
            layer.masksToBounds = corberRadius > 0
        }
    }
}

Moreover any problems can be debugged without even compelling and running the whole project, how ? Just choose, Editor and Debug selected views.

whenever we are compiling the code prepareForInterfaceBuilder and there we can make required check either the target is interface builder or else.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s