Magic Bullet Dave
Magic Bullet Dave

Reputation: 9076

Objective C class category in Interface Builder

I have created a class category in Objective C:

#import <UIKit/UIKit.h>

@interface UIView (LayerProperties)

@property IBInspectable (nonatomic) CGFloat cornerRadius;
@property IBInspectable (nonatomic) CGFloat borderWidth;
@property IBInspectable (nonatomic, strong) UIColor *borderColour;

@end

This is all good and works if I import the header. How do I get this category to show up in Interface Builder when I add a UIView?

Upvotes: 2

Views: 767

Answers (3)

Magic Bullet Dave
Magic Bullet Dave

Reputation: 9076

I was being dumb. All that is wrong is that I have put the IBInspectable macro in the wrong place in my property definition:

@property IBInspectable (nonatomic) CGFloat cornerRadius;

Should be:

@property (nonatomic) IBInspectable CGFloat cornerRadius;

Silly mistake, might help someone else save some time. Now all properties show up on all views (and view subclasses):

enter image description here

Upvotes: 2

Sudhir
Sudhir

Reputation: 127

Try this. KVC in interface builder. Maybe you need subclass

enter image description here

Or Create subclass and use IBInspectable / IBDesignable (http://nshipster.com/ibinspectable-ibdesignable/ )

Upvotes: 2

Hemang
Hemang

Reputation: 27052

You need to subclass a view where you should import this category. And then change your storyboard view with that subclassed view, all the properties from your category should be available then.

For e.g.

#import "LayerProperties+UIView.h"
@interface MyCustomView : UIView
@end

Now in IB, change your view class to MyCustomView.

Upvotes: 0

Related Questions