Active UISearchBar Turns Background Status Indicator Black

I have UISearchBara top UITableViewthat works great. I'm trying to customize its appearance, and there is a problem when the search bar is active - it turns the background color in the status bar to black. I tried the suggestions in Changing the iOS7 status bar to black after the search is active , but this did not work for me.

Example showing the black status bar

The app is only for iOS 7. UISearchBar- This is the minimum search style and default line style, translucent and the default barTintColor. I customized 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 know how to change the background color in the status bar? I want it to match the color UISearchBar.

Thank!

+4
1

, UISearchBar

on viewDidLoad()

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

    [self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];

:

- (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];
       }
     }
  }
0

Source: https://habr.com/ru/post/1546452/


All Articles