UITextField appearance doesn't work in UISearchBar - ios

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.

Related

UILabel appearance setTextColor doesn't work

I'm trying to set the color of placeholder's text in UISearchBar and I've placed [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]]; into my AppDelegate's method (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions but it doesn't work.
After that I've placed it into view controller's method where I create UISearchBar programmatically and it helps me but there's another problem: I'm creating search bars in a several view controllers and the text color of placeholder changed only for one. Actually for that who did load first and the rest of search bar placeholder's text color are still has no changes.
Can anyone explain how to change it for all search bars in project?
Try this. Tested works fine.
[searchBar setValue:[UIColor redColor] forKeyPath:#"_searchField._placeholderLabel.textColor"];

How to change background colour behind search bar

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

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

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;

Change Background Color of iOS App When Pushing Views

In my app, I use a navigation controller to switch between different views. Each of my views has an image for a background, but when I go from one to another, a little bit of white shows up in between them while transitioning. Is there a way to change that?
In the Table View Class I have this in the viewDidLoad:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"parchment.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = imageView;
[imageView release];
In the detail view I have just a standard loadrequest for an HTML. The HTML itself has the code for the parchment paper to be a background image. Here is what they look like:
But, going back from the detail view with the verses to the table view, I get this:
In your:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method of AppDelegate. assign background color to window like this:
self.window.backgroundColor = [UIColor blackColor]; // or anycolor
Have you tried changing the background color property of the view?
[[self view] setBackgroundColor:[UIColor redColor]];
The issue was in the viewWillDisappear of the web view controller. It was set to change webpage to about:blank page, which made it white. I got rid of that code, and it worked fine.
Try to set the background color of the navigation controller's view.
In your navigation controller's root view controller (I guess it's the table view controller)
self.navigationController.view.backgroundColor = // any color ;

Resources