4

I have a UISearchBar at the top of UITableView which works great. I've been trying to customise its appearance and there is an issue when the search bar is active - it turns the status bar background colour to black. I tried the suggestions in IOS7 Status bar change to black after search is active but it didn't work for me.

Example showing the black status bar

App is iOS 7-only. UISearchBar is to to Minimal Search Style and Default Bar Style, translucent and default barTintColor. I've customised its appearance in my AppDelegate as follows:

[[UISearchBar appearance] setBarTintColor:AAColorInputBorder];
[[UISearchBar appearance] setBackgroundColor:AAColorInputBorder];
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]]; 
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                         [UIColor whiteColor],NSForegroundColorAttributeName,
                         [UIFont fontWithName:@"Avenir" size:16], NSFontAttributeName,
                         nil] forState:UIControlStateNormal];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Avenir" size:14]];

Does anyone have any idea on how to change the status bar background color? I want it to match the colour of the UISearchBar.

Thanks!

Community
  • 1
  • 1
staticnz
  • 491
  • 1
  • 5
  • 15

1 Answers1

0

This is a little hack I use to extend the UISearchBar color

on viewDidLoad()

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

    [self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];

method:

- (void) removeUISearchBarBackgroundInViewHierarchy:(UIView *)view {
    for (UIView *subview in [view subviews]) {
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
           [subview removeFromSuperview];
           break; //To avoid an extra loop as there is only one UISearchBarBackground
        } else {
           [self removeUISearchBarBackgroundInViewHierarchy:subview];
       }
     }
  }
Carlo Solano
  • 103
  • 7
  • Unfortuantely didn't fix it for me. I presume this would go under `viewDidLoad`? – staticnz Sep 10 '14 at 06:43
  • I have updated my answer. I had forgotten to include a method. Also, I did not come up with this solution; I found it a while ago here and can't find the original post – Carlo Solano Sep 10 '14 at 19:17