S.Philip
S.Philip

Reputation: 446

How to setTitle of a UIButton with a specific tag?

We can get a view with a specific tag using viewWithTag method, like

[sampleView viewWithTag:1];

But how can we setTitle of a UIButton with specific tag??

From this answer here, it used the following code to set the alpha. But setTitle will not respond to viewWithTag right?

UIView* view = [theViewContainingThatButton viewWithTag:tag]; 

view.alpha = 0.5;

I even tried this question, but no luck!!

What else I can do here?

Thanx :)

Upvotes: 0

Views: 1351

Answers (2)

PengOne
PengOne

Reputation: 48398

The following should work:

UIButton *button = (UIButton *)[theViewContainingThatButton viewWithTag:tag];
[button setTitle:@"Button Title" forState:UIControlStateNormal];

Remember that a UIButton does not respond to setTitle:, but does respond to setTitle:forState:

Upvotes: 2

gamozzii
gamozzii

Reputation: 3921

UIButton* aButton = (UIButton *) [theViewContainingThatButton viewWithTag:tag]; 

[aButton setTitle:@"clickeme" forState:UIControlStateNormal];

Upvotes: 3

Related Questions