Created
May 14, 2020 08:11
-
-
Save stevencurtis/721beb2d2bf198ea2c2ade564d0433fd to your computer and use it in GitHub Desktop.
BlueView
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 BlueView: UIView { | |
var myLabel = UILabel() | |
// init from code | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
setupView() | |
} | |
// init from xib or storyboard | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
setupView() | |
} | |
// common setup code | |
private func setupView() { | |
backgroundColor = .red | |
myLabel.text = "a" | |
myLabel.textAlignment = .center | |
self.addSubview(myLabel) | |
myLabel.translatesAutoresizingMaskIntoConstraints = false | |
myLabel.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true | |
myLabel.heightAnchor.constraint(equalTo: self.heightAnchor).isActive = true | |
myLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true | |
myLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment