开发者

How to setTitle of a UIButton with a specific tag?

开发者 https://www.devze.com 2023-03-26 23:48 出处:网络
We can get a view with a specific tag using viewWi开发者_如何学CthTag method, like [sampleView viewWithTag:1];

We can get a view with a specific tag using viewWi开发者_如何学CthTag 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 :)


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

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


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:

0

精彩评论

暂无评论...
验证码 换一张
取 消