简体   繁体   English

如何使用Xcode 4.2在iOs 7中设置与导航栏颜色相同的状态栏颜色

[英]How to set status bar color same as to Navigation bar color in iOs 7 using Xcode 4.2

Now i Am using Xcode 4.2 to develop app.and the app is running on iOS 7 iPhone.My problem related with status bar color.I want the status bar color is same color as of navigation bar color.I am using this code for setting navigation bar image ,here is my code: 现在我正在使用Xcode 4.2开发应用程序,并且该应用程序在iOS 7 iPhone上运行。我的问题与状态栏颜色有关。我希望状态栏颜色与导航栏颜色相同。我正在使用此代码进行设置导航栏图片,这是我的代码:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bar.png"] forBarMetrics:UIBarMetricsDefault];

How we can set the status bar color?now is light gray color>>Many thanks.... 如何设置状态栏颜色?现在是浅灰色>>非常感谢。

In iOS6 you can't change the image or the color of the status bar apart from this 2 styles: 在iOS6中,除了这两种样式,您无法更改状态栏的图像或颜色:

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

chakra's suggestion to add the line of code: chakra建议添加代码行:

self.navigationController?.navigationBar.isTranslucent = false

works. 作品。 Add it to your function in the swift files of your controllers. 将其添加到控制器的swift文件中的函数中。 This allows the status bar to be the same color as the navigation bar. 这使状态栏与导航栏的颜色相同。 I added this as an answer instead of a comment, because I cannot add comments to other answers as yet. 我将其添加为答案而不是评论,因为目前还无法在其他答案中添加评论。 The line of code above this line of code does not work for me though. 但是,这行代码上方的代码行对我不起作用。

This works: 这有效:

self.navigationController?.navigationBar.barTintColor  = UIColor.untSimeioblue
self.navigationController?.navigationBar.isTranslucent = false

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

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