Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let codedLabel:UILabel = UILabel()
- codedLabel.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
- codedLabel.textAlignment = .center
- codedLabel.text = alertText
- codedLabel.numberOfLines=1
- codedLabel.textColor=UIColor.red
- codedLabel.font=UIFont.systemFont(ofSize: 22)
- codedLabel.backgroundColor=UIColor.lightGray
- let heightConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 200)
- let widthConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 200)
- codedLabel.addConstraints([heightConstraint, widthConstraint])
- let verticalConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: self.contentView, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0)
- let horizontalConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: self.contentView, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
- self.contentView.addConstraints([verticalConstraint, horizontalConstraint])
- self.contentView.addSubview(codedLabel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement