How to get all the textfields from a view in swift

前端 未结 8 859
予麋鹿
予麋鹿 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:39

    Swift 5
    A Very simple answer you can understand easyly : - You can handle all kind of Objects like UILable, UITextfields, UIButtons, UIView, UIImages . any kind of objecs etc.

    for subviews in self.view.subviews {
        if subviews is UITextField
        {
            //MARK: - if the sub view is UITextField you can handle here
            funtextfieldsetting(textfield: subviews as! UITextField)
        }
        if subviews is UIButton
        {
            //MARK: - if the sub view is UIButton you can handle here
            funbuttonsetting(button: subviews as! UIButton)
        }
        if subviews is UILabel
        {
            //MARK: - if the sub view is UILabel you can handle here
            //Any thing you can do it with label or textfield etc
               
         }
     }
    

提交回复
热议问题