Search code examples
iosswiftuiviewuikituilabel

UIView viewwithtag method in swift


I'm trying to learn some swift. I programmatically add labels. I want to change their properties later.

the viewwithtag method returns a UIView, how to I access my UILabel from this?

cheers


Solution

  • You need to use a typecast. This code will do it:

        if let theLabel = self.view.viewWithTag(123) as? UILabel {
            theLabel.text = "some text"
        }