1
我试图改变UIButton图像的颜色。在viewDidLoad方法中,我将着色颜色更改为“appColor”或灰色,工作正常。当用户点击按钮时,我尝试再次更改色调颜色,但没有任何反应。我甚至试图用UIButton.imageView setImage来改变图像,也没有任何反应。我究竟做错了什么?为什么不UIButton.imageView setTintColor:工作在IBAction
这工作
- (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;
}
}
我需要在tintColorDidChange中放置什么? – david2391
我试过[self setNeedsDisplay];仍然没有什么 – david2391
调用tintColorDidChange方法吗? – user1459524