如何设置具有特定标签的UIButton的标题?

时间:2011-08-11 04:21:13

标签: iphone objective-c uibutton

我们可以使用viewWithTag方法获取具有特定标记的视图,例如

[sampleView viewWithTag:1];

但是我们如何设置具有特定标签的UIButton的标题?

this answer here开始,它使用以下代码设置alpha。但是setTitle不会响应viewWithTag吗?

UIView* view = [theViewContainingThatButton viewWithTag:tag]; 

view.alpha = 0.5;

我甚至试过this question,但没有运气!!

我还能在这做什么?

Thanx:)

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:2)

以下内容应该有效:

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

请注意,UIButton不响应setTitle:,但会回复setTitle:forState: