UIView viewwithtag方法在swift中

我试图快速学习。 我以编程方式添加标签。 我想稍后改变他们的属性。

viewwithtag方法返回一个UIView,如何从这里访问我的UILabel?

干杯

你需要使用一个types转换。 这段代码将做到这一点:

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

viewWithTag:返回一个UIView,你需要将它转换成UILabel

 var yourLabel : UILabel = yourView.viewWithTag(yourTag) as UILabel; 

你需要写作

 var getMyLabel : UILabel = self.view.viewWithTag(tagValue) as UILabel;