I want to change a UIButton programmatically, is that possible?
Without any interaction.
Can I get the objects in the view somehow? If I can get them I can iterate through them and get the UIButton I want and change it to what I want to.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, this is possible.
If you’re dealing with a dynamic number of buttons, then using tags is what you need.
When inserting your
UIButton(either via Interface Builder or programatically), you can assign it a tag. As in,view.tag = 6. This means you can pull out a particular instance of your button from it’s super view.In practise, you would typically add your button via:
The additional step is assigning a tag (how you keep track of your tags is up to you).
In order to access it again, I can extract it from my view.
And this produces the same instance that I initially created.
If you wanted to replace it, you simply remove the old one, and create+add the new one.