问题描述
|
我在运行时创建UIButton,并处理按钮触摸;我想在单击按钮时更改按钮textColor,并在触摸另一个按钮时返回到原始颜色。如何以编程方式进行?
解决方法
[aButton setTitleColor:[UIColor grayColor] forState: UIControlStateNormal]
那么您可以使用与上面相同的代码,但使用不同的颜色来更改单击另一个按钮时的颜色。
, 循环浏览按钮的一种方法是在要循环浏览的按钮上设置标签。我使用以下代码为每个UITextFiles设置键盘返回键类型:
NSInteger tag = 1;
UIView *aView;
while ((aView = [contentView viewWithTag:tag])) {
if([aView isKindOfClass:[UITextField class]]){
[(UITextView *)aView setReturnKeyType:UIReturnKeySend];
}
tag++;
}
因此,我猜测您可以执行以下操作:
NSInteger tag = 1;
UIView *aView;
while ((aView = [contentView viewWithTag:tag])) {
if([aView isKindOfClass:[UIButton class]]){
[ aView setTitleColor:[UIColor grayColor] forState: UIControlStateNormal];
}
tag++;
}