- Add a new visual class to your app.
- Select the header file for the class in the Xcode project navigator, and add the attribute
IB_DESIGNABLE
above the line beginning with @interface
.
- In the Xcode project navigator, select a storyboard or xib file.
- Drag a View object (for an iOS app) or a Custom View object (for an OS X app) from the Object library to the Interface Builder canvas.
- Select the view object, and choose View > Utilities > Show Identity Inspector.
- Enter the name of the class for your custom view in the Class field of the Identity inspector (in the Custom Class area).
- Choose View > Assistant Editor > Show Assistant Editor, and use the assistant’s jump bar to navigate to the implementation file for your custom view.
- Write the code for your custom view.
- Choose View > Assistant Editor > Add Assistant Editor, and use the assistant editor’s jump bar to navigate to the header file for your custom view.
- Include the attribute
IBInspectable
with the declarations of properties that store values.
- With the custom view selected in Interface Builder, choose View > Utilities > Show Attributes Inspector.
- Change the values of the properties directly in the Attributes inspector.
参考链接: https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/Chapters/CreatingaLiveViewofaCustomObject.html