UILabel appearance setTextColor doesn't work - ios

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"];

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.

UINavigationBar not updating Color immediately

I am trying to change the color of the UINavigationBar as the User navigates to a different page. However my App does not change the color of the UINavigationBar until the user backs out of the page and goes back into the page once again. I tried putting the initialization code for changing the color in -(void)viewDidLoad and also -(void)viewWillAppear:(BOOL)animated. Here is how I am currently attempting to change the color:
-(void)viewWillAppear:(BOOL)animated{
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.32f green:0.14f blue:0.32f alpha:1.00f]];
}
You should use something like that:
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.32f green:0.14f blue:0.32f alpha:1.00f]];
}
That code you have changes title bar color for ALL UINavigationBar instances. It's application wide proxy. You don't want to use it if you need to change it in just one place.

UISplitView remove app tint color

My app is based on a UISplitViewController on iPad.
There is a functionnality which add a second UISplitViewController over the first.
But this remove the apptint.
I've tried the following code in the first split view when going back on first split view, but it does not work:
-(void)viewWillAppear:(BOOL)animated {
UIWindow *appWindow = [[UIApplication sharedApplication]keyWindow];
[appWindow setTintColor:[UIColor redColor]];
}
I heard there is a bug (8276014 in apple bug report) that seems to match my issue.
Any help?
You can also set an app’s tint color in Interface Builder. The Global Tint menu in the Interface Builder Document section of the File inspector lets you open the Colors window or choose a specific color.
or
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.tintColor = [UIColor redColor];
return YES;
}
or
In iOS 7, tint color is a property of UIView. iOS 7 apps often use a tint to define a key color that indicates interactivity and selection state for UI elements throughout the app.
When you specify a tint for a view, the tint is automatically propagated to all subviews in the view’s hierarchy. Because UIWindow inherits from UIView, you can specify a tint color for the entire app by setting the window’s tint property using code like this:
Setting the tintColor property by using the appearance proxy APIs is not supported in iOS 7.
[[UIView appearance] setTintColor:[UIColor redColor]];//iOS 6

How do you set the background color of a UINavigationbar programatically?

I am using a cocoa iOS component from cocoacontrols.com, which is NOT using storyboards. This class creates a new modal view and the modal view has a NavigationBar at the top. I am trying to get the color of the navigationBar to change. In all my other views, which are storyboard based, I use a base class of STBaseViewController which sets the navigationBar as white.
I have changed this cocoacontrol class to be a STBaseViewController instead of a UIViewController, but it still is not changing my background to white.
#interface BZPasscodeFieldController : STBaseViewController
In the BZPasscodeFieldController, which they don't make any reference to a navigationbar, so I am not sure how its even showing up (again it has no storyboard's only xibs and they don't have navigationbars)?
Anyway, does anyone know how to make the navigationbar background color white programatically?
Further, in all my storyboard viewControllers that have a UINavigationBar, I have added a UIButton over the area where the title goes, so that I can easily change the font/style and also make it clickable. I need to add this same UIButton to the uinavigationBar of this BZPasscodeFieldController created programatically. How would I go about doing that?
To Set Navigationbar Background Color:
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
To set Navigationbar Tint Color:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
For your question about the button on the place of title of navigationBar. Each navigationBar has a titleView property, you can assign any view to it. For example take a look at this method, you can call it in your BZPasscodeFieldController:
- (void) setNavigationBarTitleButton
{
UIButton* centralButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 44)];
[centralButton setImage:navigationCentralButtonImage forState:UIControlStateNormal];
[centralButton setShowsTouchWhenHighlighted:TRUE];
[centralButton addTarget:self action:#selector(goHigher) forControlEvents:UIControlEventTouchDown];
self.navigationItem.titleView = centralButton;
}
For your previous question the answers provided already are all correct, calling them in the right place(for example in AppDelegate's application:didFinishLaunchingWithOptions: should make it work well, unless something is messed up in your custom view controller classes.
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

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