Attached UISearchBar background image

I'd like to migrate my tableHeaderView based search bar to the new seamless search bar approach in iOS 11 by configuring navigationItem.searchController.


Since my navigation bar uses a custom background image, I'm wondering how to apply the same background image to the search bar as well. I tried


[navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBarPromptBackground"] forBarMetrics:UIBarMetricsDefaultPrompt];
[searchBar setBackgroundImage:[UIImage imageNamed:@"NavigationBarBackground"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];


to no avail. The search bar keeps the standard navigation bar background (with a barTintColor applied) but doesn't show the custom background image.

Replies

I do a very similar thing in my application and discovered on IOS11 it's now broken. This is the code I had which sets my image across the Search and Scope bars, works fine up to IOS10:


[searchBarSearch setBackgroundImage:image];
[searchBarSearch setScopeBarBackgroundImage:image];


I fixed it by adding this to the .plist


View controller-based status bar appearance = NO


Now my bar is coloured and changes as I select different options as it did before IOS11.

Hope this helps you!


Plasma

Good to know, but alas, going back to the legacy status bar appearance handling is not an option for me.

Did you concidere filing a bug report? Maybe this is not intended. 🙂


Dirk

I did. Radar 33145707. It's also on OpenRadar if you want to dupe it.

I have the same bug and it kills completely the UI, and the UX.

I'm so surprised that this bug exists. Very unfortunate.