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