斯威夫特:获取特定类型的所有子视图,并添加到一个数组 [英] Swift: Get all subviews of a specific type and add to an array

查看:112
本文介绍了斯威夫特:获取特定类型的所有子视图,并添加到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义类在一个UIView的按钮,我想,使他们很容易接触到添加到一个数组是有办法。获取所有子视图与特定的类,它在斯威夫特添加到一个数组?

I have a custom class of buttons in a UIView that I'd like to add to an array so that they're easily accessible is there a way to. Get all subviews of with a specific class and add it to an array in Swift?

推荐答案

使用过滤器功能运营商可以过滤特定类的物品。

The filter function using the is operator can filter items of a specific class.

let myViews = view.subViews.filter{$0 is MyButtonClass}

MyButtonClass 是要过滤的自定义类。

这篇关于斯威夫特:获取特定类型的所有子视图,并添加到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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