UIView在swift中的viewwithtag方法 [英] UIView viewwithtag method in swift

查看:125
本文介绍了UIView在swift中的viewwithtag方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力学习一些快速的东西。
我以编程方式添加标签。我想稍后更改它们的属性。

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

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

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

欢呼

推荐答案

您需要使用类型转换。这段代码会这样做:

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

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

这篇关于UIView在swift中的viewwithtag方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆