2014-09-27 122 views
3

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

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

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

enter image description here

但是它在模拟器上运行时的外观如下图所示:红色方块:

enter image description here

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

有什么建议吗? TIA。

+0

哪个你的图像的大小? – matsoftware 2014-09-27 07:18:37

回答

2

的图像。如果这是你使用的相同图像,那就是为什么它看起来像一个坚实的块。

它应具有透明背景的创建,像这样:

Icon with transparency

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

Fixed image in 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:)]; 

enter image description here

搜索图像是我的输出。

+0

请勿更改图像格式。当你下载亚创建任何图标使它.png。之后,你不要改变格式,否则会显示纯色 – 2014-09-27 07:34:04

2
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"g122.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuClieckd:)]; 

这提供具有不透明背景链接工作对我来说