Develop
2022.12.09 15:38
[swift] UIView에서 subview 찾기
Views 2122 Comment 0
UIView에서 하위의 subviews 찾아서 배열을 리턴
import UIKit
extension UIView
{
func findSubViews<T: UIView>(classOf: T.Type) -> [T] {
return recursiveSubviews.compactMap { $0 as? T }
}
var recursiveSubviews: [UIView] {
return subviews + subviews.flatMap { $0.recursiveSubviews }
}
}