Created
December 10, 2016 18:42
-
-
Save alfian0/b14aa051fedaeeb39dbaccec1e8def75 to your computer and use it in GitHub Desktop.
Swift UIView Utils - For AutoLayouting Programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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