Apple brought IB_DESIGNABLE with Xcode 6.
Its have some great improvement to interface builder.
With this feature you can design custom views via interface builder.
IB_DESIGNABLE is used to achieve live rendering of custom views using IB_DESIGNABLE and IBInspectable attributes.
In this post we will give you an overview of IB_DESIGNABLE and IBInspectable attributes.
- Create A demo App
- Open Xcode
- Create new project (File -> New ->Project -> Select IOS -> Application ->Single view Application)
- I have name this project as IBDesignables
- Now Choose a template for new file and create new Cocoa Touch Class name , i have name it as view_IBDesignable And SubClass it to UIView (File ->New->File ->iOS->Source->Cocoa Touch Class->Name it (i have choose view_IBDesignable) )
- Add the IBInspectable properties to the custom view class.
- Now select the storyboard /XIB file and drag the UIView in storyboard/XIB
- Select the newly draggle UIView and rename the custom class new (UIView)to view_IBDesignable
- Now select the attribute Inspector for the added view and change the IBInspectable lineWidth/fillColor from it and see the Output render in the UIView.
IBinspectable Supports below types:
Also apple provide Macro if you want to support older version for Xcode
Get the source Code on GitHub