我需要检查哪个图像设置为按钮背景。 可以有三个选项,基于几个因素编制程序集。 如果在某些动画后设置了特定背景,则应触发某些功能。
所以,我需要这样的东西:if(button.getBackgroundImage == certainBackgroundImage){做某事}
现在,我知道有一种方法可以将按钮背景设置为某个图像:
[button setBackgroundImage:[UIImage imageNamed:@"cloudRed.png"] forState:UIControlStateNormal];
是否有一种方法可以执行以下操作:
UIImage *red cloud = = [UIImage imageNamed:@"cloudRed.png"];
if([cloud imageForState:UIControlStateNormal] == _cloudRed ){
NSLog(@"OMG");
}
答案 0 :(得分:3)
backgroundImageForState method of UIButton returns the UIImage
- (UIImage *)backgroundImageForState:(UIControlState)state
你如何形容:
UIImage *imageToCheckFor = [UIImage imageNamed:@"someImage.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:imageToCheckFor forState:UIControlStateNormal];
// Later to Check
if ([button backgroundImageForState:UIControlStateNormal] == imageToCheckFor) {
}