Anton Stafeyev
Anton Stafeyev

Reputation: 831

IB_DESIGNABLE Is not rendering in storyboard

#import "UIViewTest.h"

@implementation UIViewTest

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


- (id) initWithCoder:(NSCoder *)coder{
    self = [super initWithCoder:coder];
    if(self){
        self.backgroundColor = UIColor.redColor;
    }
    
    return self;
    
}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if(self){
        self.backgroundColor = UIColor.redColor;
    }
    
    return self;
}

@end

I have this code which works on the device, but doesn't seem to work in IB,

IB_DESIGNABLE @interface  UIViewTest : UIView
@end

I tried setting target to be inherited, tried specifying the module but nothing seems to work.

Upvotes: 0

Views: 68

Answers (1)

matt
matt

Reputation: 535159

Implement prepareForInterfaceBuilder:

- (void)prepareForInterfaceBuilder {
    self.backgroundColor = UIColor.redColor;
}

(If the repetition bothers you, refactor.)

Upvotes: 1

Related Questions