ios - 检查 UIButton 图像

标签 ios objective-c uibutton

我正在尝试检查一些 UIButton 图像以查看它们是否是某些图像。如果是,我想将 NSString 设置为一个值,但该值始终为 null。我做错了什么?

if ([self.firstButton.currentImage isEqual:[UIImage imageNamed:@"image"]]
    && [self.secondButton.currentImage isEqual:[UIImage imageNamed:@"another_image"]]
    && [self.thirdButton.currentImage isEqual:[UIImage imageNamed:@"another_image"]]
    && [self.fourthButton.currentImage isEqual:[UIImage imageNamed:@"another_image"]]
    && [self.fifthButton.currentImage isEqual:[UIImage imageNamed:@"another_image"]]) {
     self.myString = @"some string";
}

NSLog(@"My String: %@", self.myString);

最佳答案

你可以这样做

[[self.firstButton imageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"image"]]

试试这个。这可能会有所帮助。

关于ios - 检查 UIButton 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30739002/

相关文章:

ios - 为什么 SKProductsRequestDelegate/SKRequestDelegate didFailWithError 在 NSError 上抛出 EXC_BAD_ACCESS?

ios - 使用字符串数组填充 UI TableView

objective-c - 从 osx 中的代码设置 AutoresizingMask

swift - 如何使 View 集合并立即将其转角更改为圆角?

ios - 以编程方式将 UIButton 添加到 UITableView 但按钮不显示

ios - 将 float 的 UIButton 放在 UICollectionView 之上

javascript - 如何移植 iOS 索引文件以响应原生到 android

ios - 如何创建 NSMutableArray 并为其分配特定对象?

objective-c - 你可以在 Xcode 中设置代码区域吗?

objective-c - 基于 View "Source List"NSOutlineView 字体平滑问题