cogons
7/12/2017 - 2:46 AM

manually-create-label.swift

      let codedLabel:UILabel = UILabel()
        codedLabel.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
        codedLabel.textAlignment = .center
        codedLabel.text = "b"
        codedLabel.numberOfLines=1
        codedLabel.textColor=UIColor.red
        codedLabel.font=UIFont.systemFont(ofSize: 22)
        codedLabel.backgroundColor=UIColor.lightGray
        
        back_?.addSubview(codedLabel)
        codedLabel.translatesAutoresizingMaskIntoConstraints = false
        codedLabel.heightAnchor.constraint(equalToConstant: 200).isActive = true
        codedLabel.widthAnchor.constraint(equalToConstant: 200).isActive = true
        codedLabel.centerXAnchor.constraint(equalTo: codedLabel.superview!.centerXAnchor).isActive = true
        codedLabel.centerYAnchor.constraint(equalTo: codedLabel.superview!.centerYAnchor).isActive = true