Last active
September 26, 2020 15:43
-
-
Save yabenatti/f4c3131e6c438e81c9e77721a41648a7 to your computer and use it in GitHub Desktop.
Visual Format Constraints
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
private func setupVisualConstraints() { | |
view.addSubview(titleLabel) | |
view.addSubview(hiButton) | |
let viewsDict = [ | |
"label": titleLabel, | |
"button": hiButton | |
] | |
let verticalConstraint = NSLayoutConstraint.constraints( | |
withVisualFormat: "V:|-20-[label]-[button]", | |
options: [], | |
metrics: nil, | |
views: viewsDict | |
) | |
let labelHorizontalConstraint = NSLayoutConstraint.constraints( | |
withVisualFormat: "H:|-20-[label]-20-|", | |
options: [], | |
metrics: nil, | |
views: viewsDict | |
) | |
let buttonHorizontalConstraint = NSLayoutConstraint.constraints( | |
withVisualFormat: "H:|-20-[button]-20-|", | |
options: [], | |
metrics: nil, | |
views: viewsDict | |
) | |
NSLayoutConstraint.activate(verticalConstraint) | |
NSLayoutConstraint.activate(labelHorizontalConstraint) | |
NSLayoutConstraint.activate(buttonHorizontalConstraint) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment