I have a UISearchBar and for some odd reason whenever the search bar is tapped on the status bar color changes from black to white. I don't want the status bar color to change. Any ideas? Thanks.
Asked
Active
Viewed 4,213 times
4
-
What's the structure of the `UIViewController` that contains this `UISearchBar`? – mbm29414 Jan 07 '15 at 17:58
-
@mbm29414 What do you mean by the "structure"? – mlevi Jan 07 '15 at 18:00
-
Is it a `UISearchBar` added to a standard `UIViewController`? Is it a `UISearchDisplayController`? Trying to get a feel for where the code might go to set the `UIStatusBarStyle`. – mbm29414 Jan 07 '15 at 18:02
-
In agreement with @mbm29414 . Check out [Search Bar appearance](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UISearchBar.html) – Louis Tur Jan 07 '15 at 18:06
-
@mbm29414 ahh, it's in a `UITableViewController` with `UISearchBarDelegate`. Thanks – mlevi Jan 07 '15 at 18:07
-
@LouisTur I looked at Search Bar Appearance and couldn't find anything on status bar color – mlevi Jan 07 '15 at 18:12
-
Is your `UITableViewController` embedded in a `UINaivgationController`? – mbm29414 Jan 07 '15 at 18:16
-
The accepted answer to this question (http://stackoverflow.com/questions/19129540/ios7-status-bar-change-to-black-after-search-is-active?answertab=votes#tab-top) seems to indicate that the `UISearchBar` sends a call to its "parent" `UINavigationController` when it begins editing. Can you try doing what it suggests and report back? – mbm29414 Jan 07 '15 at 18:18
-
Oh, sorry I misread the post. A really good resource is [App Coda](http://www.appcoda.com/customize-navigation-status-bar-ios-7/). You may need to implement `preferredStatusBarStyle`... maybe even in conjunction with `UISearchBarStyle` settings – Louis Tur Jan 07 '15 at 18:19
-
@LouisTur It worked! Setting the preferredStatusBarStyle somehow fixed it, thanks! – mlevi Jan 07 '15 at 18:21
-
@mbm29414 I just fixed it, I set the preferredStatusBarStyle and that seemed to get it to work! Thanks for all your help! – mlevi Jan 07 '15 at 18:22
-
Sure thing. <15 characters>. – mbm29414 Jan 07 '15 at 18:25
2 Answers
8
The accepted answer here seems to indicate that the UISearchBar
sends a call to its "parent" UINavigationController
when it begins editing.
Therefore, you seem to have 2 options:
You could simply override the
tintColor
for theUINavigationController
for youUITableViewController
, orYou could write a simple
UINavigationController
subclass that overrides-preferredStatusBarStyle
, returning the desired style.
It looks like #1 gives you what you need with minimal fuss/code.
-
1I think you can override `preferredStatusBarStyle` from any view controller, it's directly accessible without the need for subclassing. – Louis Tur Jan 07 '15 at 18:39
-
@LouisTur That hasn't been true in my experience, but I'm willing to give it a shot. – mbm29414 Jan 07 '15 at 18:57
-
I'm overriding `preferredStatusBarStyle` from a `UIViewController` that is contained within a `UINavigationController`, and it works like a charm. – Paaske Sep 11 '15 at 14:31
0
My approach is the following:
self.definesPresentationContext = YES;
and implement this function:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDarkContent;
}

gklka
- 2,459
- 1
- 26
- 53