How to change statusBar background color when search is active?

。_饼干妹妹 提交于 2021-02-19 02:13:22

问题


I've used UISearchController. When I click on the search bar, navigation bar hides and search bar goes to the top of the screen. But, it shows extra space between top of the screen and the search bar

How do I change statusBar color to default searchBar gray color ?

StatusBar font colour is white, hence when user click search bar, auto above status bar information becomes invisible.So i just need to cover that area by default gray color too, then user can see clearly the status bar.Like this


回答1:


The extra space is your status bar which you is lost in your white background.

func viewDidLoad() {
    super.viewDidLoad()
    edgesForExtendedLayout = UIRectEdge.None
}



回答2:


You can try one of following based on your implementation:

If you are using storyboards Click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.

If you are not using storyboards set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick.




回答3:


Figured it out , just need to add this code to viewDidLoad :-

definesPresentationContext = true


来源:https://stackoverflow.com/questions/32858975/how-to-change-statusbar-background-color-when-search-is-active

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