Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get subView's data in swift

Tags:

ios

swift3

I have many subviews (button,label,textField)inside view.These are dynamically created depending on the xml elements. if xml elements are 13, the total button will also be 13 buttons. i know how to search all subviews inside view and which subviews is UIButton or UITextField by the following code.

for subView in view.subviews {

if subView is UILabel {

}
else if subView is UITextField {

}

}

what i want to know is how can i get the button's tag and title and textField's text?

like image 702
noob Avatar asked Nov 17 '25 20:11

noob


1 Answers

Try this code:

for subView in view.subviews {

            if subView is UILabel {
                let label = subView as! UILabel
                let labelText = label.text

            }
            else if subView is UITextField {
                let textField = subView as! UITextField
                let textFieldText = textField.text
            }

        }
like image 58
Vishal Sonawane Avatar answered Nov 19 '25 10:11

Vishal Sonawane