UINavigationBar: Adding navigation bar not able to change color or title - ios

I add it a UINavigationBar on interface builder on my story board but I want to change the color and title of the UINavigationBar programmatically but it doesn't work. Here is my code:
self.navigationController.navigationBar.tintColor = [UIColor redColor];
self.navigationItem.title = #"New Title";
Any of you knows why this happening or a way around this?
I'll really appreciate your help.

Try:
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
These kinds of things can also be done in interface builder when you have access to the reference (and previewed)

try this code
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor blueColor]};
if you want to change navigation bar background color,
use
self.navigationController.navigationBar.barTintColor

you can also use these code to change the navigationbar in global.
[[UINavigationBar appearance] setBarTintColor:RGB(248, 248, 248)];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:COLOR_NAV_GLOBAL}];
[[UINavigationBar appearance] setBackIndicatorImage:[[UIImage imageNamed:#"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[[UIImage imageNamed:#"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:33.0/255.0 green:30.0/255.0 blue:94.0/255.0 alpha:1.0];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
put this in the view did load method.
first one is for the navigation bar tint color and the second one is for the title font color.

Related

iOS Navigation Bar background color

I am new to iOS development, I facing a strange problem. In viewDidLoad
I had written a code like this
self.navigationController.navigationBar.backgroundColor= [UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0];
this is working fine and changed the navigation bar background color, the problem is in the top of the navigation bar there is white bar showing (that has Carrier, Battery, time), I want that background color also changed... so I tried the below code
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0]];
But nothing changed, it is showing same white background color, I would like to know whats the mistake I am doing
Try this,
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
or
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
and
[self.navigationController.navigationBar setBarStyle:UIStatusBarStyleLightContent];
You should use the barTintColor property in order to change the navigation bar background color and also the status bar background color.
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0]];

Can't change backgroundcolor of navbar

In my iOS app, I'm using REFRostedViewController (https://github.com/romaonthego/REFrostedViewController) without a storyboard. It's working fine. However, I don't want the navigation bar to be blurred and so I set out to change this. I'm not having any luck though.
I tried setting self.navigationController.navigationbar.background = [UIColor blueColor] in just about any view. That makes the blur blueish.
I've been trying to fix this for about two days. What am I doing wrong?
Please try with following code in where you are initializing your NavigationController
[[UINavigationBar appearance] setTitleTextAttributes: #{
NSBackgroundColorAttributeName: [UIColor blueColor],
}];
Do you want the navigation bar to be transparent then? If you want it to have full alpha try:
self.navigationController.navigationBar.translucent = NO;
You could use:
[navigationController.navigationBar setTintColor:[UIColor redColor]]; //Red as an example.
Try by setting below property of navigaiton nar
self.navigationController.navigationBar.barTintColor = [UIColor yourColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;

QLPreviewController customise the title color of the navigation bar?

I can not create a custom QLPreviewController. Can someone help me with the code?
You can do it with appearance
Like this :
[[UINavigationBar appearance] setTitleTextAttributes:
#{NSForegroundColorAttributeName: [UIColor whiteColor]}];

Change Color of navigationBar of just UIActivityViewController

How do you change the colour of only the UIActivityViewController?
I want to change the colour of just the UINavigationBar of the UIActivityViewController using something like:
self.activityViewController.navigationController.navigationBar.barTintColor = [UIColor greenColor];
I would suggest to change the background color of the UINavigationBar before creating and presenting your UIActivityViewController with:
[UINavigationBar appearance].backgroundColor = [UIColor greenColor];
HTH
Following code maybe help you:
[[UINavigationBar appearanceWhenContainedIn:[UIActivityViewController class], nil]
setTintColor:[UIColor greenColor]];

How to change navigation bar color in iOS 7 or 6?

I want to change the color of the navigation bar color, but I'm not sure whether or not I should change the tint or the background. I know iOS 7 is going for a more flat design (even recommending removing gradients), but I am having trouble deciphering the two. Even if I set a background color, it doesn't do anything.
In this image, the background is set to green, but the bar is still blue:
The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background and behaves as described for the tintColor property added to UIView.
To tint the bar's background, please use -barTintColor.
navController.navigationBar.barTintColor = [UIColor navigationColor];
If you want to have a solid color for your navigation bar in iOS 6 similar to iOS 7 use this:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor greenColor]];
in iOS 7 use the barTintColor like this:
navigationController.navigationBar.barTintColor = [UIColor greenColor];
or
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
// In ios 7 :-
[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
// In ios 6 :-
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
The background color property is ignored on a UINavigationBar, so if you want to adjust the look and feel you either have to use the tintColor or call some of the other methods listed under "Customizing the Bar Appearance" of the UINavigationBar class reference (like setBackgroundImage:forBarMetrics:).
Be aware that the tintColor property works differently in iOS 7, so if you want a consistent look between iOS 7 and prior version using a background image might be your best bet. It's also worth mentioning that you can't configure the background image in the Storyboard, you'll have to create an IBOutlet to your UINavigationBar and change it in viewDidLoad or some other appropriate place.
One more thing, if you want to change the navigation bg color in UIPopover you need to set barStyle to UIBarStyleBlack
if([UINavigationBar instancesRespondToSelector:#selector(barTintColor)]){ //iOS7
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.barTintColor = [UIColor redColor];
}
Here is how to set it correctly for both iOS 6 and 7.
+ (void)fixNavBarColor:(UINavigationBar*)bar {
if (iosVersion >= 7) {
bar.barTintColor = [UIColor redColor];
bar.translucent = NO;
}else {
bar.tintColor = [UIColor redColor];
bar.opaque = YES;
}
}
The complete code with version checking.
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
}
else {
// do stuff for older versions than iOS 7
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
}
You can check iOS Version and simply set the tint color of Navigation bar.
if (SYSTEM_VERSION_LESS_THAN(#"7.0")) {
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
}else{
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Based on posted answered, this worked for me:
/* check for iOS 6 or 7 */
if ([[self navigationController].navigationBar respondsToSelector:#selector(setBarTintColor:)]) {
[[self navigationController].navigationBar setBarTintColor:[UIColor whiteColor]];
} else {
/* Set background and foreground */
[[self navigationController].navigationBar setTintColor:[UIColor whiteColor]];
[self navigationController].navigationBar.titleTextAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil];
}
you can add bellow code in appdelegate.m .if your app is navigation based
// for background color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];
// for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:#"FontNAme" size:20],
NSFontAttributeName, nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Insert the below code in didFinishLaunchingWithOptions() in AppDelegate.m
[[UINavigationBar appearance] setBarTintColor:[UIColor
colorWithRed:26.0/255.0 green:184.0/255.0 blue:110.0/255.0 alpha:1.0]];
I'm using following code (in C#) to change the color of the NavigationBar:
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.LandscapePhone);
NavigationController.NavigationBar.BackgroundColor = UIColor.Green;
The trick is that you need to get rid of the default background image and then the color will appear.
If you want to change a color of a navigation bar, use barTintColor property of it. In addition, if you set any color to tintColor of it, that affects to the navigation bar's item like a button.
FYI, you want to keep iOS 6 style bar, make a background image looks like previous style and set it.
For more detail, you can get more information from the following link:
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
In iOS7, if your navigation controller is contained in tab bar, splitview or some other container, then for globally changing navigationbar appearance use following method ::
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class],nil] setBarTintColor:[UIColor blueColor]];
Try the code below in the - (void)viewDidLoad of your ViewController.m
[[[self navigationController] navigationBar] setTintColor:[UIColor yellowColor]];
this did work for me in iOS 6.. Try it..
I'm not sure about changing the tint vs the background color but this is how you change the tint color of the Navigation Bar:
Try this code..
[navigationController.navigationBar setTintColor:[UIColor redColor]; //Red as an example.

Resources