在iOS中获取正确的状态栏颜色 [英] Getting correct color of status bar in ios

查看:382
本文介绍了在iOS中获取正确的状态栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在着色状态栏时遇到了一些麻烦。我有一个非常简单的应用程序,可以在两个视图之间移动。我尝试使用此代码为导航控制器的状态栏着色

Okay I am having some trouble coloring my status bar. I have a pretty simple app that moves between two views. I tried coloring the status bars of the navigation controller with this code

  [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];

但是直到我删除导航控制器的状态栏并将状态栏拖到故事板。然后,我希望状态栏与颜色匹配,所以我删除了导航控制器,它可以正常工作!我认为导航控制器状态栏不允许状态栏正确着色。但是,如果没有导航控制器,则无法添加推送序列。这就是导航控制器的外观

But it did not work until I removed the "navigation controller's" status bars and dragged status bars into the storyboard. Then I wanted the status bar to match the color so I deleted the navigation controller and it worked! I think the navigation controller status bar was not allowing the status bar to be colored correctly. However, without a navigation controller I cannot add a "push" segue. This is what it looks like with the navigation controller

这里没有

我不知道解决方案是什么,因为我认为需要导航控制器才能起作用。由于某些原因,没有显示选项。让我知道我该怎么办。谢谢!

I don't know what the solution is because I need the nav controller for this to work I think. For some reason there is no "show" option. Let me know what I should do. Thank you!

推荐答案

每个, http://www.appcoda.com/customize-navigation-status-bar-ios-7/ (尽管我们现在正在使用iOS 8,导航栏和状态栏的颜色在默认情况下是相同的。听起来您确实希望它们的颜色是相同的(这是您所说的正确的颜色吗?)。

Per, http://www.appcoda.com/customize-navigation-status-bar-ios-7/ (although we are now working with iOS 8, the color of the navigation bar and status bar are the same by default. It sounds like you really do want their colors to be the same (is this what you mean by "correct color"?).

要在情节提要中执行此操作,我将第一个UIViewController添加到情节提要中。单击此UIViewController,转到菜单,然后单击编辑器->嵌入->导航控制器。现在您将看到

To do this in storyboard, I would add your first UIViewController to the storyboard. Click this UIViewController, go up to the menu and click Editor -> Embed in -> Navigation Controller. You will see now that the Navigation Controller is the initial scene and your UIViewController is the root view controller. Then add a second UIViewController. Ctrl drag from the first UIViewController to the second view controller and create a show (push) segue.

现在更改UINavigationController的颜色。 igationController(第一个场景)。在左侧的大纲中,单击导航栏。在右侧的检查器中,您应该看到导航栏部分,其下面带有样式和色调。为了使外观看起来更立体,可以选择黑色不透明,然后将颜色更改为您喜欢的颜色。请注意,您的选择将滚动到UIViewControllers。在构建应用程序时,状态栏现在应与导航栏的颜色匹配。

Now to change the color of the UINavigationController. Click of the UINavigationController (the first scene). In the outline on the left, click on the Navigation Bar. In the inspector on the right, you should see a Navigation Bar section with Style and Tint underneath. For a solid look, you can select Black Opaque and change the tint color to whatever you like. Note that your selection will roll through to your UIViewControllers. When you build the app, the status bar should now match the color of the navigation bar.

这篇关于在iOS中获取正确的状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆