Cant set rightBarButtonItem tintColor - ios

Im attempting to set only the rightBarButtonItem of my navigationItem's on navigationBar. I'm using this code:
[self.navigationController.navigationBar setTintColor:[UIColor redColor]];
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
The second line does nothing however and both the left and right UIBarButtonItem stay red. What could be causing this issue?
I have also tried:
[self.navigationController.navigationBar setTintColor:[UIColor redColor]];
[self.rightBarButtonReferenceIBOutlet setTintColor:[UIColor whiteColor]];
I have also tried just using this line of code:
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor redColor]];
And the right bar button remains red. I cannot figure out what is causing this issue.
PS.. still no answer Set color of one UIBarButtonItem using IBOutlet
Also seems the same issue is here UIBarButtonItem setTintColor doesn't work on iOS7

Related

Change UINavigationBar's color

I'm using Objective-C. Here I need to change the background color of an UINavigationBar. And I tried this code below:
self.navigationController.navigationBar.backgroundColor = [UIColor greenColor];
But the result is:
What I want is change the color of the NavigationBar into the green color below instead of a blurry green as it is now. Someone please help me.
do like select your Naigation Bar on storyboard and change the property of bar tint in directly in inspector
Just add this code
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
Try to use appearance
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
Hope this help

In Objective C, while presenting a ViewController how to change the color of NavigationBar?

I am able to change tho color of NavigationBar by giving BackgroundColor but than I am not able change the color of StatusBar. Please provide a solution.
You should change the barTintColor instead of the background color.
[self.navigationController setBarTintColor:[UIColor redNavigationBarColor]];
Chances are that you will probably need to change also the barButton color and/or the the title color and all that should probably apply to more than one screen. So, to save you some time, if you want to globally change all these, put the code below in your app delegate
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
The code above will give you a red navigation bar with white title & buttons

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

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

UINavigationController background color changes that hide Back Button in iOS

Now I am trying to change UINavigationController background image with my custom Image.
I can change with following codes.
[navigation.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navController.png"]] atIndex:1];
So I got following pic. That pic is right and show the BarButton.
But when I go to the detailViewController , there is no BackButton. However I can tap without seeing it.
After I back to MainViewController , my UINavigationController Background is happening like following pic.
They are hiding my button. I'm thinking atIndex:1 is making this problem because Index 1 is above 0 and All button Index must be 0.
That's why all buttons are disappearing.
So how can I solve that problem? Please help.
Thanks for your help.
// not supported on iOS4
UINavigationBar *navBar = [purchaseNavController navigationBar];
if ([navBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)])
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"brnlthr_nav.jpg"] forBarMetrics:UIBarMetricsDefault];
}
Try using the appearance proxy provided by apple
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"] forBarMetrics:UIBarMetricsDefault];
that will set it for the entire application or you can use
[[self.navigationController.navigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"]];

Resources