Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Created October 11, 2019 22:56
Show Gist options
  • Save asmallteapot/503de14e84a141cfcda22d6e16a8a110 to your computer and use it in GitHub Desktop.
Save asmallteapot/503de14e84a141cfcda22d6e16a8a110 to your computer and use it in GitHub Desktop.
Playground demonstrating anchor-based layout constraints
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