Sunday, 11 November 2018

call label postion and size from outside of class (Swift4)

What I am trying to do is assign the position and size of a label from outside a class. Then within 2 separate classes call the label to add text to it. This would save time a lot of time if this would work.

let backbutton = UILabel!
backbutton.translatesAutoresizingMaskIntoConstraints = false
backbutton.leftAnchor.constraint(equalTo: _, constant: 20).isActive = true
backbutton.topAnchor.constraint(equalTo: _, constant: 125).isActive = true
backbutton.widthAnchor.constraint(equalToConstant: 50).isActive = true
backbutton.heightAnchor.constraint(equalToConstant: 50).isActive = true

class nineViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        backbutton.text = String("red")

    }
}

class two: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        backbutton.text = String("two")
    }
}



from call label postion and size from outside of class (Swift4)

No comments:

Post a Comment