BergP
BergP

Reputation: 3545

IBInspectable UIView property

Can I make my UIView @property inspectable?

@interface Superview : UIView 
    @property (nonatomic, weak, readonly) IBInspectable UIButton *stopButton;
    @property (nonatomic, weak, readonly) IBInspectable PKCircleProgressView *circleProgressView;
@end

I've created a designable view PKCircleProgressView, and I want it to be editable from the IB. Also I've created another designable view which contains PKCircleProgressView as subview, and I want it to be editable too.

Is there any way to edit circleProgressView's properties if I use Superview in the IB?

I've come out only with one idea, to create a common protocol for both views, and implement methods such as:

- (void)setProgress:(CGFloat)progress {
    self.circleProgressView.progress = progress;
}

but it is not easy to do it with every property, especially if I want to create another View that contains my Superview.

Upvotes: 3

Views: 1302

Answers (2)

Kusal Shrestha
Kusal Shrestha

Reputation: 1673

No you cannot make UIView Inspectable. The usage of IBInspectable is only for configuring "key value" coded property of an instance in a NIB or storyboard. Suppose, if UIView will be the key then what will be its value? There won't be value for UIView, so you cannot make UIView Inspectable. But we can make UIView's attributes Inspectable such as:

UIView's backgroundColor, width, height, etc

Sample project: IBDesignable and IBInspectable

Upvotes: 0

Tobias
Tobias

Reputation: 4397

IBInspectable does not support UIView or it's subtypes. It supports simple values.

If your custom progress view is IBDesignable why not set it's properties like radius and foreground color to be IBInspectable and in interface builder select the progress view and change the progress view's properties?

If your creating an IBDesignable superview you might be able to expose the inspectable properties of it's button and progress view using something like the Decorator pattern.

Apple's Documentation

Upvotes: 5

Related Questions