找到你要的答案

Q:When searchController is active, status bar style changes

Q:当searchcontroller活跃,状态栏的风格变化

Throughout my app I have set the status bar style to light content.

However, when the search controller is active, it resets to the default style:

I have tried everything to fix this, including checking if the search controller is active in an if statement, and then changing the tint color of the navigation bar to white, and setting the status bar style to light content. How do I fix this?

在我的应用程序我已经设置状态栏风格轻内容。

然而,当搜索器是活动的,它重置为默认样式:

我尽力解决这个问题,包括检查如果搜索控制器是在一个if语句,然后改变导航栏的颜色白色,并设置状态栏的风格,轻内容。我该如何解决这个问题?

answer1: 回答1:

a couple of option, and this could be a problem that is a bug, but in the mean time, have you tried this:

Option 1:

info.plist, set up the option in your info.plist for "Status bar style", this is a string value with the value of "UIStatusBarStyleLightContent"

Also, in your infor.plist, set up the variable "View controller-based status bar appearance" and set it's value to "NO"

Then, in each view controller in your app, explicitly declare the following in command in your initializers, your ViewWillAppear, and your ViewDidLoad

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

Option 2:

In your info.plist set up the option for "Status bar style" to "UIStatusBarStyleLightContent". Also, in your infor.plist, set up the variable "View controller-based status bar appearance" and set it's value to "YES"

Then, in each view controller place the following methods

override func preferredStatusBarStyle() -> UIStatusBarStyle {
            return UIStatusBarStyle.LightContent;
        }

override func prefersStatusBarHidden() -> Bool {
    return false
}

Also, you may need to do something like this:

    self.extendedLayoutIncludesOpaqueBars = true

Also, I translated it to Swift code for you

一对夫妇的选择,这可能是一个问题,是一个错误,但在同一时间,你尝试过这个:

选项1:

并设置选项,并在你的“状态栏”风格,这是一个字符串值的值“uistatusbarstylelightcontent”

同时,在你的infor.plist,设置变量视图控制器的状态栏出现“设置它的值为“否”

然后,在你应用程序中的每个视图控制器,显式声明以下你的初始值设定项,命令viewWillAppear,和你的viewDidLoad

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

选项2:

在你设置的选项中的“状态栏风格”到“uistatusbarstylelightcontent”。同时,在你的infor.plist,设置变量视图控制器的状态栏出现“设置它的值为“是”

然后,在每个视图控制器中放置以下方法

override func preferredStatusBarStyle() -> UIStatusBarStyle {
            return UIStatusBarStyle.LightContent;
        }

override func prefersStatusBarHidden() -> Bool {
    return false
}

此外,你可能需要这样做:

    self.extendedLayoutIncludesOpaqueBars = true

此外,我翻译成SWIFT代码为你

answer2: 回答2:

Add this to your code to make the status bar style to Light :

   override func preferredStatusBarStyle() -> UIStatusBarStyle {

            return UIStatusBarStyle.LightContent;
        }

You can also set the status bar in the info list and it will remain same in you app until it is override in the code for paticular view controller.

将此添加到您的代码中以使状态栏样式变为光:

   override func preferredStatusBarStyle() -> UIStatusBarStyle {

            return UIStatusBarStyle.LightContent;
        }

你也可以在信息列表设置状态栏,它会在你的应用程序保持不变直到它覆盖在代码的特殊视图控制器。

ios  swift