【问题标题】:UIBarButtonItem image not displayed but a red square is insteadUIBarButtonItem 图像未显示,但显示为红色方块
【发布时间】:2013-10-29 04:02:17
【问题描述】:

我正在尝试使用图像和 UIBarButtonItem 类在单元格中显示右箭头(Apple 的方式)。问题是显示的图像不是显示的图像,而是与图像大小相同的红色正方形。我尝试使用另一个图像来更改图像,结果又得到了另一个与另一个图像具有相同大小(这次是圆角)的红色正方形。

我的代码如下:

UIImage *arrowImage = [UIImage imageNamed:@"arrow.png"];

UIBarButtonItem *runItem = [[UIBarButtonItem alloc] initWithImage:arrowImage style:UIBarButtonItemStyleBordered handler:^(id sender) {

    [self pushListWithID:[(DIDList *)_fetcher.fetchedObjects[indexPath.row] idValue] runMode:NO];

}];

[(UIToolbar *)cell.accessoryView setItems:@[runItem]];

我检查了这个,但它并没有真正帮助ios UIBarButtonItem with UIBarButtonSystemItemCompose showing red button

有谁知道如何解决这个问题?

【问题讨论】:

    标签: ios uitableview uibarbuttonitem uitoolbar


    【解决方案1】:

    您可以检查图像的大小和分辨率,使其完全适合您的按钮。 我怀疑您的图像是否大于要安装在 barButton 中的实际尺寸

    【讨论】:

    • 我尝试使用 40 x 40 像素的图像(iOS Retina 设备需要),然后使用 20 x 20 像素的图像......他们都没有解决问题......
    • 尝试添加 UIButton 而不是 UIBarButton。
    • 我认为直接使用 UITableViewCellAccessoryDisclosureIndicator 会更简单。知道如何调整我的代码以使用它而不是图像吗?
    【解决方案2】:

    这与您的具体问题无关,但我遇到了类似的问题,并希望将我的解决方案传递给其他人。当我加载汉堡包图标的 JPEG 文件时,我得到了一个红色方块。我尝试将其大小调整为 20 x 20,但没有帮助。如果我拥有它的原始形式,那么 512 x 512 会占据很多屏幕。

    我最终找到了图片的 PNG 版本 (http://www.appdesignvault.com/ios-7-button-design/),而且效果很好。所以文件格式可能是相关的,但您已经在使用 PNG,所以这不适用于您的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-08
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 2011-11-26
      相关资源
      最近更新 更多