Reputation: 9527
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?
Upvotes: 0
Views: 843
Reputation: 11201
You don't have to set constraints to make the width equal.
Just set the constraints for the elements in the xib so that they will get aligned according to their superview frame.
And you can set the xib view frame in the awakeFromNib method.
Upvotes: 1