我尝试在导航面板上显示png
图像。我确实如下:
UIImage *img = [UIImage imageNamed:@"1.png"];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(myAction)];
self.navigationItem.rightBarButtonItems = @[myButton];
img
不是nil
,但是myButton
是白色正方形。这个正方形的大小与我的image
的大小相同,但没有显示图像,只是一个白色正方形。我有一个用于视网膜图像的@2x
版本,我选择了我的项目作为这两个图像的目标。
什么可能是什么?
检查工具栏和导航栏图标的人际接口指南(可选):
无论图标的视觉样式如何
大约22 x 22像素(标准分辨率)
大约44 x 44像素(2x)
大约66 x 66像素(3x)
代码:
UIImage *image = [UIImage imageNamed:@"image.png"];
UIImage *newImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithImage:newImage style:UIBarButtonItemStylePlain target:self action:@selector(myAction)];
self.navigationItem.rightBarButtonItems = @[myButton];
UIImage *img = [UIImage imageNamed:@"1"];**//1.png previously**
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(myAction)];
self.navigationItem.rightBarButtonItems = @[myButton];
只需删除.png简单地给出图像名称即可起作用。