Skip to content

Instantly share code, notes, and snippets.

@CharlesAE
Created October 14, 2018 07:24
Show Gist options
  • Save CharlesAE/1fc1ec3d7f5c9e4304e22bd345103578 to your computer and use it in GitHub Desktop.
Save CharlesAE/1fc1ec3d7f5c9e4304e22bd345103578 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
extension UIView {
public func addConstraintsWithFormat(_ format: String, views: UIView...) {
var viewsDictionary = [String: UIView]()
for (index, view) in views.enumerated() {
let key = "v\(index)"
viewsDictionary[key] = view
view.translatesAutoresizingMaskIntoConstraints = false
}
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: 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