Created
October 11, 2019 22:56
-
-
Save asmallteapot/503de14e84a141cfcda22d6e16a8a110 to your computer and use it in GitHub Desktop.
Playground demonstrating anchor-based layout 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
import PlaygroundSupport | |
import UIKit | |
final class LabelViewController: UIViewController { | |
var label: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.backgroundColor = .systemBackground | |
label = UILabel() | |
label.text = "418 i'm a teapot" | |
label.textColor = .placeholderText | |
label.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(label) | |
NSLayoutConstraint.activate([ | |
label.centerXAnchor.constraint(equalTo: view.centerXAnchor), | |
label.centerYAnchor.constraint(equalTo: view.centerYAnchor), | |
]) | |
} | |
} | |
PlaygroundPage.current.liveView = LabelViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment