【问题标题】:UIBarButtonItem Custom IconUIBarButtonItem 自定义图标
【发布时间】:2014-09-27 07:15:55
【问题描述】:

我使用以下行来创建一个 UIBarButtonItem 和一个名为 import2x.png 的自定义图标:

UIBarButtonItem *btnImport = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"import2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnImport)];

图标是一个看起来像这样的 png:

但这是它在模拟器上运行时的样子 - 一个实心红色方块:

图标是使用透明 (alpha=0) 背景创建的。

有什么建议吗? TIA。

【问题讨论】:

  • 你的图片尺寸是多少?

标签: ios icons


【解决方案1】:

所提供链接中的图像具有不透明的背景。如果您使用的是同一张图片,这就是为什么它看起来像一个实心块。

应该用透明背景创建,像这样:

即在 Photoshop 中,您应该能够看到这样的背景图案:

【讨论】:

    【解决方案2】:

    试试这个。它工作正常。我还分享了我的输出截图。你必须使用小尺寸的图标。但是图标应该是可见的,没问题。

     UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Login-pin.png"] landscapeImagePhone:[UIImage imageNamed:@"Login-pin.png"] style:UIBarButtonItemStylePlain target:self action:@selector(PickerCancelClick:)];
    

    搜索图像是我的输出。

    【讨论】:

    • 不要更改图像格式。当你下载你创建任何图标使其成为.png。之后你不要改变格式,否则它会显示纯色
    【解决方案3】:
    self.navigationItem.rightBarButtonItem =  [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"g122.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuClieckd:)];
    

    这对我有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 2012-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      相关资源
      最近更新 更多