Skip to content

Instantly share code, notes, and snippets.

@mlvea
Created September 28, 2015 13:45
Show Gist options
  • Save mlvea/b4552073cfa1f2812149 to your computer and use it in GitHub Desktop.
Save mlvea/b4552073cfa1f2812149 to your computer and use it in GitHub Desktop.
UIView extension to bind subview bounds to its superview
extension UIView{
func boundInside(superView: UIView){
self.translatesAutoresizingMaskIntoConstraints = false
superView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[subview]-0-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics:nil, views:["subview":self]))
superView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[subview]-0-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics:nil, views:["subview":self]))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment