更改UISearchController上的状态栏颜色

时间:2015-06-28 06:36:11

标签: ios objective-c

我试图更改iOS 8搜索栏的状态栏颜色,但我尝试了UIStatusBarStyleLightContent没有运气,谁都知道更好的方法? Example of how it looks right now

2 个答案:

答案 0 :(得分:1)

从iOS 10开始(可能更早?),如果在Info.plist中将“基于控制器的状态栏状态显示”设置为YES,只需在UIViewController中设置包含UISearchController的preferredStatusBarStyle。 / p>

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

(您不需要子类化或创建UISearchController的类别/扩展来覆盖preferredStatusBarStyle ...它使用您在UIViewController中设置的preferredStatusBarStyle)

答案 1 :(得分:0)

你试过这个吗?

self.yourSearchBar.backgroundColor = UIColor.blueColor()

编辑:

要更改状态栏,您可以更改Info.plist或覆盖preferredStatusBarStyle函数

<key>UIViewControllerBasedStatusBarAppearance</key>
  <false/>
<key>UIStatusBarStyle</key>
  <string>UIStatusBarStyleLightContent</string>

OR

    override func preferredStatusBarStyle() -> UIStatusBarStyle
    {
        return UIStatusBarStyle.LightContent;
    }
相关问题