Last active
November 12, 2016 11:47
-
-
Save genedelisa/12819f1c4c9428c5348b to your computer and use it in GitHub Desktop.
Programmatic autolayout constraints
This file contains hidden or 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
// the frame size doesn't matter; autolayout will change it | |
var aButton = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) | |
aButton.titleLabel?.text = "HEY" | |
aButton.opaque = true | |
aButton.backgroundColor = UIColor.yellow | |
view.addSubview(aButton) | |
aButton.translatesAutoresizingMaskIntoConstraints = false | |
let margins = view.layoutMarginsGuide | |
aButton.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor, constant: -0).active = true | |
aButton.bottomAnchor.constraintEqualToAnchor(bottomLayoutGuide.topAnchor, constant: -30).active = true | |
aButton.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor, constant: 8.0).active = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment