Created
December 4, 2015 09:08
-
-
Save onmyway133/fcf892aac565d36ee890 to your computer and use it in GitHub Desktop.
UILayoutGuide_Spacing.swift
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
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Buttons | |
let saveButton = UIButton() | |
saveButton.translatesAutoresizingMaskIntoConstraints = false | |
saveButton.setTitle("Save", forState: .Normal) | |
saveButton.setTitleColor(UIColor.blackColor(), forState: .Normal) | |
view.addSubview(saveButton) | |
saveButton.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor).active = true | |
saveButton.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true | |
let cancelButton = UIButton() | |
cancelButton.translatesAutoresizingMaskIntoConstraints = false | |
cancelButton.setTitle("Cancel", forState: .Normal) | |
cancelButton.setTitleColor(UIColor.blackColor(), forState: .Normal) | |
view.addSubview(cancelButton) | |
cancelButton.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor).active = true | |
let clearButton = UIButton() | |
clearButton.translatesAutoresizingMaskIntoConstraints = false | |
clearButton.setTitle("Clear", forState: .Normal) | |
clearButton.setTitleColor(UIColor.blackColor(), forState: .Normal) | |
view.addSubview(clearButton) | |
clearButton.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor).active = true | |
clearButton.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor).active = true | |
// Constraints | |
let space1 = UILayoutGuide() | |
view.addLayoutGuide(space1) | |
let space2 = UILayoutGuide() | |
view.addLayoutGuide(space2) | |
space1.widthAnchor.constraintEqualToAnchor(space2.widthAnchor).active = true | |
saveButton.trailingAnchor.constraintEqualToAnchor(space1.leadingAnchor).active = true | |
cancelButton.leadingAnchor.constraintEqualToAnchor(space1.trailingAnchor).active = true | |
cancelButton.trailingAnchor.constraintEqualToAnchor(space2.leadingAnchor).active = true | |
clearButton.leadingAnchor.constraintEqualToAnchor(space2.trailingAnchor).active = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment