[英]How do I make navigation bar button item show my custom image as is?
How do I make navigation bar button item show my custom image as is? 如何使导航栏按钮项显示我的自定义图像? Using the code below my button shows up as a solid color. 使用下面的代码我的按钮显示为纯色。 The outline of the image shows up correctly. 图像的轮廓正确显示。
UIImage *image = [UIImage imageNamed:@"image.png"];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(onButtonTapped:)];
self.navigationItem.leftBarButtonItem = buttonItem;
If you are on iOS7 try to change the UIImage's rendering mode 如果您在iOS7上尝试更改UIImage的渲染模式
UIImage *image = [UIImage imageNamed:@"image.png"];
UIImage *newImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
use newImage to init the bar button item 使用newImage来初始化栏按钮项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.