我们可以使用viewWithTag方法获取具有特定标记的视图,例如
[sampleView viewWithTag:1];
但是我们如何设置具有特定标签的UIButton的标题?
从this answer here开始,它使用以下代码设置alpha。但是setTitle不会响应viewWithTag吗?
UIView* view = [theViewContainingThatButton viewWithTag:tag];
view.alpha = 0.5;
我甚至试过this question,但没有运气!!
我还能在这做什么?
Thanx:)
答案 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: