遍历所有子控件

遍历一个控件中的所有子控件,可以使用递归的思想

func find(view: AnyClass, inView: UIView, finished: @escaping (_ view: UIView) -> Void) {
      for subview in inView.subviews {
            
          if subview.isKind(of: view.self) {
              finished(subview)
          }
            
          find(view: view, inView: subview, finished: finished)
      }
}

使用

find(view: UITextField.self, inView: self) { (view) in
        // view is UITextField
}

你可能感兴趣的:(遍历所有子控件)