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