Swift:如何检测 UIView 中的元素? [英] Swift: How can I detect elements inside of a UIView?

查看:28
本文介绍了Swift:如何检测 UIView 中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道两件事(我是 Swift 初学者):

I am wondering two things (I am a Swift beginner):

1) 有没有办法检测或目标元素(子元素)在给定的 UIView 内.

1) Is there a way to detect or target elements (children) are inside a give UIView.

2) UIView 中的元素是否存储在数组中?

2) Are the elements inside the UIView stored in an array?

举个例子,假设我有一个名为 parentView 的 UIView,它有一个 ImageView(称为 imageChildre)和一个 LabelView(称为labelChildre)

As an example let say I have a UIView called parentView and it has inside an ImageView (called imageChildre) and a LabelView (called labelChildre)

我如何定位孩子?

感谢您的帮助

推荐答案

  1. 这样的事情?您可以相应地更改条件.

  1. Something like this? You can change condition accordingly.

for subview in parentView.subviews
{
    if let item = subview as? UIImageView
    {
        //this is image view
    }
}

  • parentView.subviewsparentView

    这篇关于Swift:如何检测 UIView 中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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