Status bar tint color changes to black in iOS 6

坚强是说给别人听的谎言 提交于 2019-12-18 03:43:36

问题


I am apparently not understanding how to use the status bar tint in iOS 6. I have read this question: Change statusbar tint colour but implementing the solutions suggested there has not resolved the issue.

I have configured the settings in the target summary pane (default for style and tinting) and added the status bar tint parameters dictionary to my info.plist as described in WWDC 2012 Advanced Appearance Customization.

My status bar tints correctly at launch but once I navigate to another view controller the status bar changes to black.

The second view controller is embedded in its own navigation controller. Could this be the root of the issue?

Whatever the cause, I am hoping that someone can offer a solution that will allow me to make my status bar be tinted consistently throughout my application.

Please let me know if anything needs clarification and thanks in advance for any assistance.


回答1:


Today I ran into the same issue, but none of the sugested answers would help me.

Since I defined my own color (red, blue, green, alpha), I did not want to add a UIStatusBar via IB, I need a one-line-solution.

After testing for a while the following worked for me:

  1. In the Project Summary select Status Bar Style Black Transculent from the drop down menu.
  2. In application: didFinishLaunchingWithOptions: enter the following line of code:

    self.window.backgroundColor = [UIColor redColor]; //example color

Somehow this would not work for me when setting the style via code in application: didFinishLaunchingWithOptions:

Enjoy!




回答2:


One solution is to put an invisible navigation bar in front of your interface. You might have to subclass UINavigationController if you're in a navigation interface already. For example:

UINavigationBar* nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,320,1)];
nav.tintColor = [UIColor redColor];
nav.alpha = 0;
[self.navigationBar.superview addSubview:nav];

This causes the status bar to be red, regardless of the tint or background color of the navigation bar. This works also if there is no navigation bar.

Credit where credit is due; I got the idea of setting alpha to 0 from https://stackoverflow.com/a/13587525/341994.




回答3:


The second view controller is embedded in its own navigation controller. Could this be the root of the issue?

This is most likely the issue - but I also would have thought the plist entry would make it global. Have you tried setting it programatically using UIAppearance (assuming you only support ios6+)?

[[UITabBar appearance] setTintColor:[UIColor redColor]];


来源:https://stackoverflow.com/questions/12965214/status-bar-tint-color-changes-to-black-in-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!