简体   繁体   English

如何使导航栏按钮项显示我的自定义图像?

[英]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.

相关问题 如何在iOS的导航项中显示后退栏按钮项? - How do I get the back bar button item to show up in my navigation item in iOS? 如何使导航栏上的“添加”按钮执行某些操作? - How do I make the “Add” button on a navigation bar do something? 如何隐藏/显示导航栏中的右键 - How do I hide/show the right button in the Navigation Bar 如何在TableView的顶部制作一个导航栏 - How do I make a navigation bar at the top of my TableView 如何加快在导航项中启用“条形按钮”项的请求? - How can I speed up my request to enabled a Bar Button Item in Navigation Item? 如何将左栏按钮项设置为用透明导航栏填充为黑色? - How do I set the left bar button item to be filled in black with a transparent Navigation Bar? 如何在右侧导航栏项目上设置带有背景图像的圆形按钮 - How to set circle button with background image on right navigation bar item 如何根据TableView行删除来更改导航栏按钮项的状态 - How do i change the navigation bar button item state according to tableview row delete 如何在Xcode中更改导航栏项目(特别是按钮)的宽度? - How do I change the width of the navigation bar item (specifically a button) in Xcode? 导航左栏按钮项作为图像徽标 - Navigation Left Bar Button Item as Image Logo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM