Xcode6: IBDesignable and IBInspectable with Object

2019-01-30 06:30发布

问题:

I have an Objective-C UI component that I'd like to make inspectable in Interface Builder with Xcode 6. Swift has the @IBDesignable and @IBInspectable declaration attributes. Are they available also in Objective-C? How are they used?

回答1:

The equivalents are IB_DESIGNABLE and IBInspectable—see the documentation for Objective C examples.

Also, this year's WWDC video "What's New in Interface Builder" has its examples in Swift, but the presenter also mentions the Objective C equivalents in passing.



回答2:

Code example:

#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface LOLView : UIView
@property (nonatomic) IBInspectable UIColor *someColor; 
@end