I have a storybaord with a UIView
that has a class set to MyView
(this class is defined as @interface MyView : UIView
).
In class MyView
, I have this construction:
-(void)awakeFromNib{
[super awakeFromNib];
[[UINib nibWithNibName:@"MyNib" bundle:nil] instantiateWithOwner:self options:nil];
[self addSubview:self.contentView];
}
It loads design from nib and add contentView
to it. Now, how can I set contentView
width to be the same as width of self
? I have tried add constraint programatically under addSubview
method, but app crashed.
So where should I add constraint and how the code should be?