I understand that this question has been asked many, many times on SO. However, since Apple is doing everything possible with the release of iOS 11 , they seem to have made an unnecessary change for the UISearchBar , in particular the presentation hierarchy.
In addition, the βtext boxβ of the search bar is no longer available in the subzones of the search bar, resulting in all previous solutions βaccessingβ and changing the background color of the text box or any property of the text box.
- Does anyone know how to actually adjust the background color of the search bar in iOS 11 ?
FYI: I specifically talk about the color behind the text ... which is now 11 by default equal to white unless you specify the search bar style as minimal.
UPDATE 1:
From my publication of this question, I still have not found a real or really no real solution . The closest thing that seems to me is to plunge deeply into the appearance, for example, properties
[[UISearchBar class] appearanceWhenContainedInInstancesOfClasses:(nonnull NSArray<Class<UIAppearanceContainer>> *)]
UISearchBar . Play with the found UITextField using methods such as:
if ([view isKindOfClass:[UITextField class]]) { return (UITextField*)view; } UITextField *searchTextField; for (UIView *subview in view.subviews) { searchTextField = [self searchViewForTextFieldBg:subview]; if (searchTextField) { break; } } return searchTextField;
You can start drawing a background view of a new one that will be placed behind the view. However, the problems, which I found too tedious to continue further, outlined the view with the correct frames to accurately simulate the original background.
Hope someone finds a real solution to this problem. Nice miss apple ...
ios objective-c swift ios11 uisearchbar
Will von ullrich
source share