How to get all the textfields from a view in swift

前端 未结 8 858
予麋鹿
予麋鹿 2020-12-17 17:53

I have a view which has more than 15 UITextFields. I have to set bottomBorder(extension) for all the UITextFields. I can set it one by one for all

8条回答
  •  不思量自难忘°
    2020-12-17 18:22

    try this

    for aSubView: Any in self.view.subviews {
    if (aSubView is UITextField) {
        var textField = (aSubView as! UITextField)
        textField. setBottomBorder()
    }
    }     
    

    or try this

    for view in self.view.subviews {
    if (view is UITextField) {
         var textField = view as! UITextField
          textField. setBottomBorder()
    }
    }
    

提交回复
热议问题