简体   繁体   English

UIBarButtonItem着色颜色与设备上的颜色不同

[英]UIBarButtonItem tint color not same color on device

I have at least one UIBarButtonItem's in every UIViewController in my project, everything is in a UINavigationController and the UINavigationBar is blue and the UIBarButtonItem's should be white. 我的项目中的每个UIViewController中至少都有一个UIBarButtonItem's ,所有内容都在UINavigationController中, UINavigationBar为蓝色,而UIBarButtonItem's应该为白色。

In the simulator they are white... but in device they are lightgray as you can see in the pictures below: 在模拟器中,它们是白色的...但是在设备中,它们是浅灰色的,如下图所示:

Simulator 仿真器 仿真器

Device 设备 设备

They run the exact same code and the exact same ios version ios 8.1 . 他们运行完全相同的代码和完全相同的ios版本ios 8.1

I am currently setting the tint color in storyboard to white, but Ive also tried: 我目前将情节提要中的色调设置为白色,但Ive也尝试过:

// In appdelegate
UINavigationBar.appearance().barTintColor = UIColor(hex: 0x4a9bcb, alpha: 1.0)
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName:UIFont(name: "FuturaLT-Bold", size: 16)!, NSForegroundColorAttributeName:UIColor(white: 1.0, alpha: 1.0)]
UIBarButtonItem.appearance().tintColor = UIColor.whiteColor()

// In map viewcontroller viewDidLoad 
self.edgesForExtendedLayout = UIRectEdge.None
self.navigationController?.navigationBar.translucent = false

Which gave the same result. 给出了相同的结果。

Please help me understand whats going on. 请帮助我了解发生了什么。

I found what was wrong.......... In settings there is an option under General/Accessibility/Increase Contrast called Darker colors... I had that turned on which made tint color darker (of course). 我发现问题出在哪里..........在设置中,“常规” /“辅助功能” /“增加对比度”下有一个名为“较暗的颜色”的选项。我打开了该选项,使色调颜色变暗了(当然)。 So silly. 真傻。

That is most likely due to alpha (transparency) being on for the top NavigationBar. 这很可能是由于顶部NavigationBar的alpha(透明度)处于启用状态。 When the content slides under the top bar it shows a percentage of the underlying view causing your whites to not be white. 当内容在顶部栏下滑动时,它会显示一定比例的基础视图,导致您的白人不是白人。

You can eliminate that by turning transparency on the NavigationBar off: 您可以通过关闭NavigationBar上的透明度来消除这种情况:

self.navigationController.navigationBar.translucent = NO;

or by stopping the content from scrolling under the bar by setting: 或通过设置以下内容停止滚动条下方的内容:

edgesForExtendedLayout = UIRectEdgeNone;

See this StackOverflow answer for more details and an explanation of extended layout and transparent navigation bars. 有关更多详细信息以及扩展布局和透明导航栏的说明,请参见此StackOverflow答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM