我可以更改图像但是当我回到这个视图时,它会在我选择UIControlState时显示与UIControlStateNormal相同的图像。
-(IBAction) favorateImage:(UIButton*)sender{
AppDelegate *obj=[[UIApplication sharedApplication]delegate];
if ([sender isSelected]) {
[sender setImage:[UIImage imageNamed:@"favrtes_uncheck.png"] forState:UIControlStateNormal];
[sender setSelected:NO];
NSMutableArray* array = [[[NSUserDefaults standardUserDefaults] objectForKey:@"favoriteItems"] mutableCopy];
[array removeObject:[NSNumber numberWithInt:self.number]];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"favoriteItems"];
NSLog(@"%@", array);
obj.country_main= array;
} else
{
[sender setImage:[UIImage imageNamed:@"favrtes_detail.png"] forState:UIControlStateSelected];
[sender setSelected:YES];
NSMutableArray* array= [[[NSUserDefaults standardUserDefaults] objectForKey:@"favoriteItems"] mutableCopy];
[array addObject:[NSNumber numberWithInt:self.number]];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"favoriteItems"];
NSLog(@"%@", array);
obj.country_main= array;
}
}
答案 0 :(得分:0)
您可以使用UIControlStateHighlighted。
[sender setImage:[UIImage imageNamed:@"favrtes_detail.png"] forState:UIControlStateHighlighted];
您也可以通过将图像设置为突出显示状态来从界面构建器设置此项。