iOS 7, scope bar becomes black in search mode

2019-05-10 15:27发布

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.

2条回答
狗以群分
2楼-- · 2019-05-10 16:21

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.

查看更多
唯我独甜
3楼-- · 2019-05-10 16:31

I have resolved this problem by using UISearchBar appearance:

[[UISearchBar appearance] setBackgroundImage:bgImage forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
查看更多
登录 后发表回答