Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. let codedLabel:UILabel = UILabel()
  2. codedLabel.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
  3. codedLabel.textAlignment = .center
  4. codedLabel.text = alertText
  5. codedLabel.numberOfLines=1
  6. codedLabel.textColor=UIColor.red
  7. codedLabel.font=UIFont.systemFont(ofSize: 22)
  8. codedLabel.backgroundColor=UIColor.lightGray
  9.  
  10. let heightConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 200)
  11.  
  12. let widthConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 200)
  13.  
  14. codedLabel.addConstraints([heightConstraint, widthConstraint])
  15.  
  16. let verticalConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: self.contentView, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0)
  17.  
  18. let horizontalConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: self.contentView, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
  19.  
  20. self.contentView.addConstraints([verticalConstraint, horizontalConstraint])
  21.  
  22. self.contentView.addSubview(codedLabel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement