ryryan
ryryan

Reputation: 3928

Setting Search Bar to non-translucent

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.

Upvotes: 2

Views: 430

Answers (1)

matt
matt

Reputation: 535129

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.

Upvotes: 1

Related Questions