Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift. Useful UIView extension for adding constraints with format
extension UIView {
func addConstraintsWithFormat(format: String, views: UIView...) {
var viewsDict = [String: UIView]()
for (index, view) in views.enumerated() {
view.translatesAutoresizingMaskIntoConstraints = false
viewsDict["v\(index)"] = view
}
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDict))
}
func addConstraintsFillEntireView(view: UIView) {
addConstraintsWithFormat(format: "H:|[v0]|", views: view)
addConstraintsWithFormat(format: "V:|[v0]|", views: view)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.