Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyView: UIView {
- let kLabelHorizontalInsets: CGFloat = 20.0
- let kLabelVerticalInsets: CGFloat = 20.0
- var didSetupConstraints = false
- var titleLabel: UILabel = UILabel.newAutoLayoutView()
- var bodyLabel: UILabel = UILabel.newAutoLayoutView()
- override init() {
- super.init()
- self.setupViews()
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.setupViews()
- }
- required init(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- self.setupViews()
- }
- func setupViews() {
- self.backgroundColor = UIColor.redColor()
- self.addSubview(self.getTitleLabel(title: "FooBar"))
- self.addSubview(self.getBodyLabel(title: "Test"))
- self.updateFonts()
- }
- override func updateConstraints() {
- if !didSetupConstraints {
- self.titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: kLabelHorizontalInsets)
- self.titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelVerticalInsets)
- self.bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: self.titleLabel, withOffset: 0)
- self.bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets)
- self.didSetupConstraints = true
- }
- super.updateConstraints()
- }
- func getTitleLabel(#title: String) -> UILabel {
- self.titleLabel = UILabel.newAutoLayoutView()
- self.titleLabel.numberOfLines = 1
- self.titleLabel.text = title
- self.titleLabel.backgroundColor = UIColor.greenColor()
- return self.titleLabel
- }
- func getBodyLabel(#title: String) -> UILabel {
- self.bodyLabel = UILabel.newAutoLayoutView()
- self.bodyLabel.numberOfLines = 0
- self.bodyLabel.text = title
- self.bodyLabel.backgroundColor = UIColor.yellowColor()
- return self.bodyLabel
- }
- func updateFonts() {
- self.titleLabel.font = UIFont.boldSystemFontOfSize(20)
- self.bodyLabel.font = UIFont.systemFontOfSize(18)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement