Skip to content

Instantly share code, notes, and snippets.

@Kievkao
Created February 8, 2016 09:53
Show Gist options
  • Select an option

  • Save Kievkao/a2a0f4456e8ff78c9827 to your computer and use it in GitHub Desktop.

Select an option

Save Kievkao/a2a0f4456e8ff78c9827 to your computer and use it in GitHub Desktop.
Pin view to it's superview's layoutGuides
func pinnedConstraints(view: UIView) -> [NSLayoutConstraint] {
let topConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.topLayoutGuide, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.bottomLayoutGuide, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
return [topConstraint, leftConstraint, bottomConstraint, rightConstraint]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment