title: How to add equal width and equal height constraints programmatically in swift?
body: <p>Could anyone help me I have this simple view that is very simple to do if I'm using story board but all of my UILabel is based on somewhere(API) that is why I need to create my view programmatically.</p>
  <p>this is the view I would like to achieved</p>
  <p><a href="https://i.stack.imgur.com/Bc751.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bc751.png" alt=" " /></a></p>
  <p>what I accomplished at the moment are pinning the top label in its position and adding leading space on label 1, 2, &amp; 3</p>
  <p>basically what i need are:</p>
  <ol>
  <li>pin the label 1 to the top label</li>
  <li>pin the label 3 to bottom</li>
  <li>add vertical spaces to label 1,2,3</li>
  <li>have equal width and height constraint in label 1,2 ,3</li>
  </ol>
  <p>this is my code so far.</p>
  <pre><code> private func addTopConstraint(from:AnyObject,to:AnyObject,cons:CGFloat){
     let topConstraint =  NSLayoutConstraint(item: from, attribute: .Top, relatedBy: .Equal, toItem: to, attribute: .Bottom, multiplier: 1.0, constant: cons)
      self.view.addConstraint(topConstraint)
  }
  
  private func addVerticalSpace(from:AnyObject,to:AnyObject,cons:CGFloat){
      let verticalSpace = NSLayoutConstraint(item: from, attribute: .Bottom, relatedBy: .Equal, toItem: to, attribute: .Bottom, multiplier: 1.0, constant: cons)
  
      self.view.addConstraint(verticalSpace)
  }
  private func addLeadingSpace(from:AnyObject,to:AnyObject,cons:CGFloat){
      let leadingSpace = NSLayoutConstraint(item: from, attribute: .Leading, relatedBy: .Equal, toItem: to, attribute: .Leading, multiplier: 1.0, constant: cons)
      self.view.addConstraint(leadingSpace)
  }
  
  
  
  
   private func sameWidthAndHeight (from:AnyObject,to:AnyObject){
             let width = NSLayoutConstraint(item: from, attribute: .Width, relatedBy: .Equal, toItem: to, attribute: .Width, multiplier: 1.0, constant: 0)
             let height = NSLayoutConstraint(item: from, attribute: .Height, relatedBy: .Equal, toItem: to, attribute: .Height, multiplier: 1.0, constant: 0)
              
              self.view.addConstraint(width)
              self.view.addConstraint(height)
          }
  </code></pre>
  <p>but the <code>sameWidthAndHeight</code> and <code>addVerticalSpace</code> function fails</p>
  <p>maybe it something to do with content hugging and priorities too, I'm not that sure since we're used to do this in storyboard.</p>
  <p>could anyone share a thought? Thanks in advance</p>