Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the element by Tag from iOS?

I want to get back a button, I've already assign the tag to there, how can I do so?

like image 519
DNB5brims Avatar asked Sep 07 '10 09:09

DNB5brims


2 Answers

Use the viewWithTag method. e.g. if your button is in your controller's view and your button's tag is 100 the following line will return the button:

UIButton *button = (UIButton *)[self.view viewWithTag:100];

EDIT:

Get view with particular tag in Swift -

let view = self.view.viewWithTag(100)

If you want to make sure you have the specific type of view, say a UIButton, you should check the type:

if let button = self.view.viewWithTag(100) as? UIButton {
    //Your code
}
like image 174
Swapnil Luktuke Avatar answered Nov 14 '22 05:11

Swapnil Luktuke


UIButton *button=(UIButton *)[self.view viewWithTag:tag]; 

//Now you can get your button based on tag value

like image 5
vntstudy Avatar answered Nov 14 '22 07:11

vntstudy