IB_DESIGNABLE & IBInspectable attributes with Objective-C, XCODE6



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.

  1. Create  A demo App
  2. Open Xcode
  3. Create new project (File -> New ->Project -> Select IOS -> Application ->Single view Application)
  4. I have name this project  as IBDesignables
  5. 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) )
  6. Add the IBInspectable properties to the custom view class.
  7. Now select the storyboard /XIB file and drag the UIView in storyboard/XIB
  8. Select the newly draggle UIView and rename the custom class new (UIView)to view_IBDesignable
  9. 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:

  • Int
  • CGFloat
  • Double
  • Bool
  • CGPoint
  • CGSize
  • CGRect
  • String
  • UIImage
  • UIColor

Also apple provide Macro if you want to support older version for Xcode

#ifndef IBInspectable

  #define IBInspectable

#endif

Get the source Code on GitHub



Add a Comment

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