title: How do I create constraints programmatically in Swift?
body: <p>I am trying to set up the width of a <code>UIButton</code> using this code:</p>
  <pre><code>constraintButtonPlayWidth = NSLayoutConstraint(item: buttonPlay,
          attribute: NSLayoutAttribute.Width,
          relatedBy: NSLayoutRelation.Equal,
          toItem: self.view,
          attribute: NSLayoutAttribute.Width,
          multiplier: 1,
          constant: 100)
  self.view.addConstraint(constraintButtonPlayWidth)
  </code></pre>
  <p>But the button gets stretched too much; probably because <code>toItem: self.view</code>. I tried modifying the constant of the constraint, but that didn't change anything.</p>
  <p>How do I set up correctly this constraint so it actually has a width of 100?</p>