xcode 导航栏按钮项目色调
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22790612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Navigation Bar Button Item Tint
提问by I'm Joe Too
Is it possible to drag a navigation bar button item to the navigation bar, use an image, and NOT have tint applied so that the original image appears as intended? Or is this only possible by adding nav bar button items via code?
是否可以将导航栏按钮项拖动到导航栏,使用图像,并且不应用色调,以便原始图像按预期显示?或者这只能通过代码添加导航栏按钮项目来实现?
Example: My dark background nav bar has white as the default tint, but I have an orange image icon I want to appear for one of the buttons. If I drag a bar button item & set the image, it appears white. Can I change (or remove) the tint for this one button? Or, do I need to forget the visual editor and create this button programmatically to control the tint?
示例:我的深色背景导航栏的默认色调为白色,但我想为其中一个按钮显示一个橙色图像图标。如果我拖动一个条形按钮项目并设置图像,它会显示为白色。我可以更改(或删除)这个按钮的色调吗?或者,我是否需要忘记可视化编辑器并以编程方式创建此按钮来控制色调?
回答by lootsch
If you want to keep the original colors of the image, you have to do it in code:
如果要保留图像的原始颜色,则必须在代码中进行:
[button setImage:[[UIImage imageNamed:@"imageName.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
If you want to overwrite the tint color of your button (e.g.: orange only) you can achieve that inside your storyboard. Just set the tint
color of your Bar Button Item
inside Xcode's Attributes Inspector
to the desired color:
如果您想覆盖按钮的色调(例如:仅限橙色),您可以在故事板中实现。只需将内部 Xcode 的tint
颜色设置为所需的颜色:Bar Button Item
Attributes Inspector
回答by brookinc
回答by mgm
To keep the original colours of the image, you would have to assign the image to the button from code rather than from your storyboard.
为了保持图像的原始颜色,您必须通过代码而不是故事板将图像分配给按钮。
- Reference your Button Outlet in your class file (usually a ViewController)
Assign the image to the button from code:
[self.bbiHome setImage:[[UIImage imageNamed:@"icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- 在您的类文件(通常是 ViewController)中引用您的 Button Outlet
将图像从代码分配给按钮:
[self.bbiHome setImage:[[UIImage imageNamed:@"icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];