请检查我是否尝试过,但这会更改整个颜色,但不会更改搜索栏背景。
1. try with navigation searchcontroller searchbar
2. my uisearchcontroller searchbar
1.
if (@available(iOS 11.0, *)) {
self.navigationItem.searchController=nil;
self.navigationItem.searchController.searchBar.backgroundColor=nil;
self.navigationItem.searchController.searchBar.barTintColor=nil;
self.navigationItem.searchController = self.searchControllerInvoice;
[self.searchControllerInvoice.searchBar setBackgroundColor:UIColor.redColor];
[self.searchControllerInvoice.searchBar setBarTintColor:UIColor.yellowColor];
[self.searchControllerInvoice.searchBar setTintColor:UIColor.greenColor];
} else {
self.getInvoiceTable.tableHeaderView = self.searchControllerInvoice.searchBar;
}
OR
2.
if (@available(iOS 11.0, *)) {
self.navigationItem.searchController=nil;
self.navigationItem.searchController.searchBar.backgroundColor=nil;
self.navigationItem.searchController.searchBar.barTintColor=nil;
self.navigationItem.searchController = self.searchControllerInvoice;
[self.navigationItem.searchController.searchBar setBackgroundColor:UIColor.redColor];
[self.navigationItem.searchController.searchBar setBarTintColor:UIColor.yellowColor];
[self.navigationItem.searchController.searchBar setTintColor:UIColor.greenColor];
} else {
self.getInvoiceTable.tableHeaderView = self.searchControllerInvoice.searchBar;
}