Skip to content

Instantly share code, notes, and snippets.

@alfian0
Created December 10, 2016 18:42
Show Gist options
  • Save alfian0/b14aa051fedaeeb39dbaccec1e8def75 to your computer and use it in GitHub Desktop.
Save alfian0/b14aa051fedaeeb39dbaccec1e8def75 to your computer and use it in GitHub Desktop.
Swift UIView Utils - For AutoLayouting Programmatically
extension UIView {
func addConstarintsWithFormat(format: String, views: UIView...) {
var viewsDictionary = [ String : UIView ]()
for (index, view) in views.enumerate() {
let key = "v\(index)"
viewsDictionary[key] = view
view.translatesAutoresizingMaskIntoConstraints = false
}
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment