【发布时间】:2014-03-31 02:01:55
【问题描述】:
我正在尝试更改 UIButton 图像的颜色。在 viewDidLoad 方法中,我将色调颜色更改为“appColor”或灰色,效果很好。当用户点击按钮时,我尝试再次更改色调颜色,但没有任何反应。我什至尝试使用 UIButton.imageView setImage 更改图像,但也没有任何反应。我做错了什么?
这行得通
- (void)viewDidLoad{
if ([checkActivityArray containsObject:[place objectId]]){
[checkCount setTextColor:appColor];
checkButton.imageView.image = [checkButton.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[checkButton.imageView setTintColor:appColor];
}
else{
[checkCount setTextColor:[UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1]];
checkButton.imageView.image = [checkButton.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[checkButton.imageView setTintColor:[UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1]];
}
}
这不是
- (IBAction)checkMarkButton:(UIButton *)sender {
sender.enabled = NO;
CheckMarkController *checkMark = [[CheckMarkController alloc]init];
BOOL didComplete = NO;
if ([checkActivityArray containsObject:[place objectId]]){
didComplete = [checkMark removeCheckMark:place];
}else{
didComplete = [checkMark addCheckMark:place];
}
if (didComplete) {
checkActivityArray = [[NSMutableArray alloc] initWithContentsOfFile:checkMarkArrayFileName];
int tempInt = [checkCount.text intValue];
if ([checkActivityArray containsObject:[place objectId]]){
[sender.imageView setImage:[checkButton.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[sender.imageView setTintColor:appColor];
[checkCount setTextColor:appColor];
tempInt++;
checkCount.text = [NSString stringWithFormat:@"%d", tempInt];
}
else{
sender.imageView.image = [sender.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[sender.imageView setTintColor:[UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1]];
[checkCount setTextColor:[UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1]];
tempInt--;
checkCount.text = [NSString stringWithFormat:@"%d", tempInt];
}
sender.enabled = YES;
}
}
【问题讨论】:
标签: ios objective-c uiimageview uibutton