Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView viewwithtag method in swift [closed]

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

like image 695
tchnvkng Avatar asked Sep 11 '25 04:09

tchnvkng


1 Answers

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

    if let theLabel = self.view.viewWithTag(123) as? UILabel {
        theLabel.text = "some text"
    }
like image 59
Adam Avatar answered Sep 12 '25 18:09

Adam