iOS 7, scope bar becomes black in search mode

2019-05-10 16:07发布

问题:

I use UISearchDisplayController embedded to UiTableViewController to make a search bar in my table view. But if I set the search bar's background image, the scope bar do not show in search mode, but showing a black bar instead. It's very weird because it does not happen in iOS 6.

Note that the image I used to set the search bar's background image is 640x90 px, somehow the scope bar will show if use other image.

Even if I set the scope bar background image, it sill not show depend on the search bar's image setting.

I think it's a bug in iOS 7, and to prevent from other factors, I even use the master-detail template in Xcode 5, and embed the UISearchDisplayController in master view controller, change the search bar background image and scope bar shows black in search mode.

I think it has something to do with iOS 7 auto resize of view controller. Bothers me so much.

Someone please try and help. Thanks a lot a lot.

------------------------------edited-------------------------- Sometimes the scope bar will show if I change search bar background image, but in real device (iPhone5), the scope bar never show.

回答1:

I have just found a solution here: IOS7 Status bar change to black after search is active

Just put these two lines on your table view controller (viewDidLoad):

self.navigationController.view.backgroundColor = [UIColor whiteColor]; 

self.navigationController.navigationBar.translucent = NO;

Where "whiteColor" is the color that you need for the status Bar.



回答2:

I have resolved this problem by using UISearchBar appearance:

[[UISearchBar appearance] setBackgroundImage:bgImage forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];