How to change background colour behind search bar - ios

I trying to customize my UISearchBar in iOS7/8 and I've met next problem:
the background behind my searchDisplayController is always light grey. This is how it looks like:
And this is my code of some search bar customization:
self.searchDisplayController.searchResultsTableView.backgroundColor = UIColorFromRGB(0x171717);
self.searchDisplayController.searchContentsController.view.backgroundColor = UIColorFromRGB(0x171717);
self.searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.searchDisplayController.searchResultsTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Is there any way to fix it? Thanks.

As it turned out this gray/white background is part of refreshControl. So all what you have to do is init it and set the needed background color:
self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.backgroundColor = UIColorFromRGB(0x232323);

You can change it programmatically using this:
[searchBar setTintColor:[UIColor darkGrayColor]];
Or try from Storyboard by changing Bar Tint:

Try by changing the tint color of the searchable in xib
or in code as [self.searchDisplayController setTintColor:[UIColor whiteColor]];searchDisplayController

Related

UITextField appearance doesn't work in UISearchBar

I'm trying to set background color for a text field inside a search bar. At first I did this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[UITextField appearanceWhenContainedInInstancesOfClasses:#[[UISearchBar class]]].backgroundColor = [UIColor blueColor];
return YES;
}
and it doesn't work. The color remains white. Ok. I got it working by calling this code:
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
self.tableView.tableHeaderView = searchBar;
[UITextField appearanceWhenContainedInInstancesOfClasses:#[[UISearchBar class]]].backgroundColor = [UIColor blueColor];
from viewDidLoad. But it works only once. When opening another view controller of this class the background color remains unchanged.
You can try it yourself. Just create a simple template iOS app and add UISearchBar. Then try to set background color for its text field via UIAppearance.
What's wrong? Is it an iOS bug? I know I can traverse through all the search bar's subviews, find UITextField and set its background color but I want to find out what's happening.

searchbar changes color when in navigation bar

I added a search bar in the titleview of a navigationitem. Searching works properly, but when using the navigation controller, the background of the searchbar changes colors, as seen below
The only place that I touch color is to change the color of the navigation item in the storyboard via xcode
the relevant code for putting the searchbar in the titleview
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
[_searchController.searchBar sizeToFit];
self.navigationItem.titleView = _searchController.searchBar;
What is causing this coloration?
trying to change the bartint color with
[_searchController.searchBar setBarTintColor:[UIColor clearColor]];
but I am getting this
also things that aren't working are
[_searchController.searchBar setBarTintColor:self.navigationController.navigationBar.tintColor];
_searchController.searchBar.backgroundColor = self.navigationController.navigationBar.tintColor;
and with backgroundColor
it seems that this color is somehow other than the settings. See here with redColor
Need to set UISearchBar tint color.
UISearchBar *search=[[UISearchBar alloc]initWithFrame:CGRectMake(10, 20, 100, 20)];
[search setBarTintColor:[UIColor clearColor]];
search.backgroundImage=[UIImage new];
self.navigationItem.titleView=search;
Now navigation bar looks like below image :
For Swift Users , just add these two lines :-
searchBar.barTintColor = UIColor.clearColor()
searchBar.backgroundImage = UIImage()
self.navigationItem.titleView = searchBar

Setting the tint color when using form sheet modal presentation does not work on iPad

I have a UISearchBar in a modal UIViewController that has presentationStyle set to UIModalPresentationStyleFormSheet.
Setting the tint colour on the search bar is only obeyed on the iphone. The iPad still ends up using the app tint color. Any reason why this is happening?
_searchBar = [[UISearchBar alloc] init];
_searchBar.tintColor = [UIColor whiteColor];
why dont you try appearance for search bar in applicationlaunch.
[[UISearchBar appearance] setTintColor:[UIColor whiteColor]];
That didn't work for me. What worked was setting the UITextField appearance, but that's iOS7 only. You can also loop over the bar's subviews and change the UITextField's tintColor:
[[UITextField appearance] setTintColor:[UIColor blackColor]];

UITextField with inputView showing UIPickerView... how to turn off translucency in IOS 7?

We have a tab bar. In one of the controllers, we have a UITextField. Clicking on that brings up a picker, using the inputView field of the UITextField. My team likes the look of that on iOS 6, but on iOS 7 they see the blurred background and tab bar coming through. Can I turn off that translucency, and where do I need to do that?
self.termsPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43, 320, 480)];
self.termsPickerView.delegate = self;
self.termsPickerView.dataSource = self;
[self.termsPickerView setShowsSelectionIndicator:YES];
self.termTextField.inputView = self.termsPickerView ;
self.termTextField.delegate = self;
UIPickerView in iOS 7.0 is translucent by default and that is the nature, and like all other views, is simple a background color controlling the color.
So to fix your problem you could do,
self.pickerView.backgroundColor = [UIColor whiteColor];
The apple documentation doesn't show any means of turning this transparency off.
tabBarController.tabBar.translucent = NO;

How to change UIWebview bottom toolbar color?

I have created a UIWebview in my app. I managed to change the background color of the navigation bar with setTintColor. However, I am unable to do the same for the bottom bar (with back/forward/refresh buttons). Can anyone help?
Did you create the bottom bar yourself? It probably is an UIToolbar:
UIToolbar *bottomToolbar = [[UIToolbar alloc] init];
bottomToolbar.tintColor = [UIColor redColor];

Resources