Last active
June 12, 2018 15:00
-
-
Save SashaTsebrii/cff8f3ddc9ff3bc5b92d9f9396502903 to your computer and use it in GitHub Desktop.
Create label and set layout programmatically.
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
class ViewController: UIViewController { | |
// MARK: - Properties | |
let titleLabel: UILabel = { | |
let textLabel = UILabel() | |
textLabel.text = "Monday" | |
textLabel.font = UIFont.boldSystemFont(ofSize: 34) | |
textLabel.textAlignment = .center | |
return textLabel | |
}() | |
// MARK: - Lifecycle | |
override func loadView() { | |
super.loadView() | |
view.addSubview(titleLabel) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupLyout() | |
} | |
// MARK: - Private functions | |
private func setupLyout() { | |
titleLabel.translatesAutoresizingMaskIntoConstraints = false | |
titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true | |
titleLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: view.bounds.height * 0.1).isActive = true | |
titleLabel.widthAnchor.constraint(equalToConstant: view.bounds.width).isActive = true | |
titleLabel.heightAnchor.constraint(equalToConstant: view.bounds.height * 0.1).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment