2

I am using a searchDisplayController in my tableview. I have got the functionality to work, I am now configuring the UI.

I would like the search bar (including the scope bar) red and the text white. I have done this through Interface Builder, which looks fine.

Upon building this, it appears like so (ignore the white block in tableview): enter image description here

The colour should be like this, which Interface Builder produces.

enter image description here

The search bar is translucent. I have unchecked Translucent for the search bar.

Reading this answer, I have tried putting

self.searchDisplayController.searchBar.translucent = NO;

in my viewDidLoad and also viewWillAppear. Unfortunately neither worked.

Nothing seems to be working. I have tried this under iOS7 and iOS7.1.

Any help would be great.

Community
  • 1
  • 1
ryryan
  • 3,890
  • 13
  • 43
  • 72
  • These are just suggestions. I find it sometimes helps to give the search bar a background image, such as a small black rectangle. Also, here's another weird idea: try configuring the search bar in one of your search display controller's delegate methods, such as `searchDisplayController:willShowSearchResultsTableView:`. – matt Mar 16 '14 at 16:18
  • Hi @matt, unfortunately neither of your suggested methods worked. – ryryan Mar 16 '14 at 20:20
  • 1
    I am seeing the same issue as OP. Setting a background image works as a workaround, but it seems like a bug that `UISearchBar` does not respect its `translucent` property. – Jamie Forrest May 08 '14 at 20:06

1 Answers1

1

The following works for me to make a search bar opaque red:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(10,10), YES, 0);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor redColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0,0,10,10));
UIImage* red = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
searchBar.backgroundImage = red;

It works for me including in your situation, i.e. a search bar that belongs to a UISearchDisplayController with a table view controller.

matt
  • 515,959
  • 87
  • 875
  • 1,141