开发者

iPhone: how can I swap UIButton text color?

I'm creating UIButtons at runtime and i handle button to开发者_如何学Cuch; I would like to change the button textColor when the button is clicked and to return to original color when another button is touched; how can I do it programmatically?


[aButton setTitleColor:[UIColor grayColor] forState: UIControlStateNormal]

then you can change the color when another button is clicked by using the same code as above but with a different color.


One way to cycle through the buttons would be to set tags on the buttons you want to cycle through. I use this bit of code to setup my keyboard return key types for each of my UITextFiles:

NSInteger tag = 1;  
UIView *aView;
while ((aView = [contentView viewWithTag:tag])) {  
    if([aView isKindOfClass:[UITextField class]]){
        [(UITextView *)aView setReturnKeyType:UIReturnKeySend];
    }
    tag++;  
}

So I'm guessing you could do something like this:

NSInteger tag = 1;  
UIView *aView;
while ((aView = [contentView viewWithTag:tag])) {  
    if([aView isKindOfClass:[UIButton class]]){
        [ aView setTitleColor:[UIColor grayColor] forState: UIControlStateNormal];
    }
    tag++;  
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜