title: UITextField autolayout with margins programmatically
body: <p>I'm new to AutoLayout and would like to display my UITextField at 100% width with a consistent 15px left and right margin, like so:</p>
  
  <p><a href="https://i.stack.imgur.com/nakqj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nakqj.png" alt="enter image description here"></a></p>
  
  <p>Typically I would do this using CGRect, setting the width to the containing view's width minus 30px, then offset the left side by 15px:</p>
  
  <pre><code>searchTextField.frame = CGRectMake(15, 0, view.frame.width - 30, 50)
  </code></pre>
  
  <p>But I'd like to learn AutoLayout for this sort of thing, since it's the way to go these days. I should note that I am doing everything programmatically -- no Storyboards here.</p>
  
  <p>I'd love it if someone could help me out!</p>
  
  <p><strong>Update</strong></p>
  
  <p>Wow! Thank you for all the responses. I believe all of them would achieve what I'm trying to do, but there can only be one :)</p>