Changing Tint / Background color of UITabBar - ios

The UINavigationBar and UISearchBar both have a tintColor property that allows you to change the tint color (surprising, I know) of both of those items. I want to do the same thing to the UITabBar in my application, but have found now way to change it from the default black color. Any ideas?

iOS 5 has added some new appearance methods for customising the look of most UI elements.
You can target every instance of a UITabBar in your app by using the appearance proxy.
For iOS 5 + 6:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
For iOS 7 and above, please use the following:
[[UITabBar appearance] setBarTintColor:[UIColor redColor]];
Using the appearance proxy will change any tab bar instance throughout the app. For a specific instance, use one of the new properties on that class:
UIColor *tintColor; // iOS 5+6
UIColor *barTintColor; // iOS 7+
UIColor *selectedImageTintColor;
UIImage *backgroundImage;
UIImage *selectionIndicatorImage;

I have been able to make it work by subclassing a UITabBarController and using private classes:
#interface UITabBarController (private)
- (UITabBar *)tabBar;
#end
#implementation CustomUITabBarController
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:kMainColor];
[v setAlpha:0.5];
[[self tabBar] addSubview:v];
[v release];
}
#end

I have an addendum to the final answer. While the essential scheme is correct, the trick of using a partially transparent color can be improved upon. I assume that it's only for letting the default gradient to show through. Oh, also, the height of the TabBar is 49 pixels rather than 48, at least in OS 3.
So, if you have a appropriate 1 x 49 image with a gradient, this is the version of viewDidLoad you should use:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *v = [[UIView alloc] initWithFrame:frame];
UIImage *i = [UIImage imageNamed:#"GO-21-TabBarColorx49.png"];
UIColor *c = [[UIColor alloc] initWithPatternImage:i];
v.backgroundColor = c;
[c release];
[[self tabBar] addSubview:v];
[v release];
}

When you just use addSubview your buttons will lose clickability, so instead of
[[self tabBar] addSubview:v];
use:
[[self tabBar] insertSubview:v atIndex:0];

There is no simple way to do this, you basically need to subclass UITabBar and implement custom drawing to do what you want. It is quite a bit of work for the effect, but it may be worth it. I recommend filing a bug with Apple to get it added to a future iPhone SDK.

Following is the perfect solution for this. This works fine with me for iOS5 and iOS4.
//---- For providing background image to tabbar
UITabBar *tabBar = [tabBarController tabBar];
if ([tabBar respondsToSelector:#selector(setBackgroundImage:)]) {
// ios 5 code here
[tabBar setBackgroundImage:[UIImage imageNamed:#"image.png"]];
}
else {
// ios 4 code here
CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *tabbg_view = [[UIView alloc] initWithFrame:frame];
UIImage *tabbag_image = [UIImage imageNamed:#"image.png"];
UIColor *tabbg_color = [[UIColor alloc] initWithPatternImage:tabbag_image];
tabbg_view.backgroundColor = tabbg_color;
[tabBar insertSubview:tabbg_view atIndex:0];
}

On iOS 7:
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:(38.0/255.0) green:(38.0/255.0) blue:(38.0/255.0) alpha:1.0]];
I also recommend setting first depending on your visual desires:
[[UITabBar appearance] setBarStyle:UIBarStyleBlack];
The bar style puts a subtle separator between your view content and your tab bar.

[[self tabBar] insertSubview:v atIndex:0];
works perfectly for me.

for me its very simple to change the color of Tabbar like :-
[self.TabBarController.tabBar setTintColor:[UIColor colorWithRed:0.1294 green:0.5686 blue:0.8353 alpha:1.0]];
[self.TabBarController.tabBar setTintColor:[UIColor "YOUR COLOR"];
Try this!!!

[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];

for just background color
Tabbarcontroller.tabBar.barTintColor=[UIColor redcolour];
or this in App Delegate
[[UITabBar appearance] setBackgroundColor:[UIColor blackColor]];
for changing color of unselect icons of tabbar
For iOS 10:
// this code need to be placed on home page of tabbar
for(UITabBarItem *item in self.tabBarController.tabBar.items) {
item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
Above iOS 10:
// this need to be in appdelegate didFinishLaunchingWithOptions
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];

There are some good ideas in the existing answers, many work slightly differently and what you choose will also depend on which devices you target and what kind of look you're aiming to achieve. UITabBar is notoriously unintuitive when it come to customizing its appearance, but here are a few more tricks that may help:
1). If you're looking to get rid of the glossy overlay for a more flat look do:
tabBar.backgroundColor = [UIColor darkGrayColor]; // this will be your background
[tabBar.subviews[0] removeFromSuperview]; // this gets rid of gloss
2). To set custom images to the tabBar buttons do something like:
for (UITabBarItem *item in tabBar.items){
[item setFinishedSelectedImage:selected withFinishedUnselectedImage:unselected];
[item setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
}
Where selected and unselected are UIImage objects of your choice. If you'd like them to be a flat colour, the simplest solution I found is to create a UIView with the desired backgroundColor and then just render it into a UIImage with the help of QuartzCore. I use the following method in a category on UIView to get a UIImage with the view's contents:
- (UIImage *)getImage {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [[UIScreen mainScreen]scale]);
[[self layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
3) Finally, you may want to customize the styling of the buttons' titles. Do:
for (UITabBarItem *item in tabBar.items){
[item setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
[UIFont boldSystemFontOfSize:18], UITextAttributeFont,
nil] forState:UIControlStateNormal];
}
This lets you do some adjustments, but still quite limited. Particularly, you cannot freely modify where the text is placed within the button, and cannot have different colours for selected/unselected buttons. If you want to do more specific text layout, just set UITextAttributeTextColor to be clear and add your text into the selected and unselected images from part (2).

[v setBackgroundColor ColorwithRed: Green: Blue: ];

Another solution (which is a hack) is to set the alpha on the tabBarController to 0.01 so that it is virtually invisible yet still clickable. Then set a an ImageView control on the bottom of the MainWindow nib with your custom tabbar image underneath the alpha'ed tabBarCOntroller. Then swap the images, change colors or hightlight when the tabbarcontroller switches views.
However, you lose the '...more' and customize functionality.

Hi There am using iOS SDK 4 and i was able to solve this issue with just two lines of code and it's goes like this
tBar.backgroundColor = [UIColor clearColor];
tBar.backgroundImage = [UIImage imageNamed:#"your-png-image.png"];
Hope this helps!

if ([tabBar respondsToSelector:#selector(setBackgroundImage:)]) {
// ios 5 code here
[tabBar setBackgroundImage:[UIImage imageNamed:#"image.png"]];
}
else {
// ios 4 code here
CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *tabbg_view = [[UIView alloc] initWithFrame:frame];
UIImage *tabbag_image = [UIImage imageNamed:#"image.png"];
UIColor *tabbg_color = [[UIColor alloc] initWithPatternImage:tabbag_image];
tabbg_view.backgroundColor = tabbg_color;
[tabBar insertSubview:tabbg_view atIndex:0];
}

Swift 3.0 answer: (from Vaibhav Gaikwad)
For changing color of unselect icons of tabbar:
if #available(iOS 10.0, *) {
UITabBar.appearance().unselectedItemTintColor = UIColor.white
} else {
// Fallback on earlier versions
for item in self.tabBar.items! {
item.image = item.image?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
}
}
For changing text color only:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.red, for: .selected)

Swift 3 using appearance from your AppDelegate do the following:
UITabBar.appearance().barTintColor = your_color

Related

iOS 7 tabBar-line, how to remove it?

Apple has added a tiny line over the tabBar in iOS 7 which is supposed to work as a shadow or fade between the tabBar and the UI
Since I am using a custom-made tabBar the line is quite irritating. How do you remove it? Please tell me it is possible, otherwise I need to redesign my whole app lol....
/ Regards
*Edit
Sloved my problem with the following line of code:
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
UIImage* tabBarBackground = [UIImage imageNamed:#"tabbar_bg.png"];
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
These code works pretty well for me (I don't really have background image for tab bar):
[tab_main.tabBar setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
And I use these code to add a frame too:
UIColor* color_green = UIColorFromRGB(0x348e5b);
tab_main.tabBar.layer.borderWidth = 0.50;
tab_main.tabBar.layer.borderColor = color_green.CGColor;
[[UITabBar appearance] setTintColor:color_green];
Hope that helps.
In iOS 8 the top border can be removed by setting the tab bar style to black in the inspector.
Swift
Nice simple solution:
Write this below code in your custom tab bar class. Then it will hide horizontal shadow line.
self.tabBar.setValue(true, forKey: "_hidesShadow")
Objective C
[self.tabBar setValue:#(YES) forKeyPath:#"_hidesShadow"];
self.tabBarController = [[UITabBarController alloc] init];
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:#"YOURIMAGE.png"]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
I'm not seeing anything in the UITabBar API for affecting that separator, but if the separator is within the UITabBar (a UIView subclass), I'd expect you can insert a new one-pixel-high UIView on top of it. You'd have to grab a slice of the image that you want to appear there and draw it in the new view. And I'm not sure if UITabBar would somehow prevent adding the subview or prevent the subview from being on top. But that's where I'd start.
Add the following code in AppDelegate.m didFinishLaunchingWithOptions: method
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
This worked for me
UIImage* tabBarBackground = [UIImage new];
if(!OSVersionIsAtLeastiOS7())
{
tabBarBackground = [UIImage imageNamed:#"whitebg"];
}
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tabtarsprnt"]]; //your custom image
[self.tabBarController.tabBar setClipsToBounds:YES];
this code also solved the my issue
In my case I also needed to set a different shadow, in the end the only thing that worked while also setting a custom shadow was to add a single-point high UIView 1 point above the tab bar:
UIView *whiteLine = [[UIView alloc] initWithFrame:CGRectMake(0.0, -1.0, self.tabBar.frame.size.width, 1.0)];
whiteLine.backgroundColor = [UIColor whiteColor];
[self.tabBar addSubview:whiteLine];
Try this,
** Objective-C **
//Remove shadow image by assigning nil value.
[[UITabBar appearance] setShadowImage: nil];
// or
// Assing UIImage instance without image reference
[[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];
** Swift **
//Remove shadow image by assigning nil value.
UITabBar.appearance().shadowImage = nil
// or
// Assing UIImage instance without image reference
UITabBar.appearance().shadowImage = UIImage()
Here is apple document for shadowImage.
#available(iOS 6.0, *)
open var shadowImage: UIImage?
Default is nil. When non-nil, a custom shadow image to show instead of
the default shadow image. For a custom shadow to be shown, a custom
background image must also be set with -setBackgroundImage: (if the
default background image is used, the default shadow image will be
used).
now you can use it, with this line:
self.tabBarController.tabBar.barStyle = UIBarStyleBlack;

iOS 7 UIBarButton back button arrow color

I'm trying to change the back button arrow
I'm currently using the following to control the text size as well as the text color on the back button:
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont boldSystemFontOfSize:16.0f], UITextAttributeFont,
[UIColor darkGrayColor], UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(0.0, -1.0)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
but if I want to change only the arrow's color for the back button, what should i do?
To change the back button chevron color for a specific navigation controller*:
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
*If you are using an app with more than 1 navigation controller, and you want this chevron color to apply to each, you may want to use the appearance proxy to set the back button chevron for every navigation controller, as follows:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
And for good measure, in swift (thanks to Jay Mayu in the comments):
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
You have to set the tintColor of the entire app.
self.window.tintColor = [UIColor redColor];
Or in Swift 3:
self.window?.tintColor = UIColor.blue
Source: iOS 7 UI Transition Guide
You can set the color on the entire app navigation's bar using the method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions{
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
It is possible to change only arrow's color (not back button title's color) on this way:
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor blackColor]];
Navigation bar contains subview of _UINavigationBarBackIndicatorView type (last item in subviews array) which represents arrow.
Result is navigation bar with different colors of back button arrow and back button title
If you are using storyboards you could set the navigation bar tint colour.
Inside the rootViewController that initializes the navigationController, I put this code inside my viewDidAppear method:
//set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
//set back button arrow color
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
In iOS 6, tintColor tinted the background of navigation bars, tab bars, toolbars, search bars, and scope bars. To tint a bar background in iOS 7, use the barTintColor property instead.
iOS 7 Design Resources iOS 7 UI Transition Guide
You can set the tintColor property on the button (or bar button item) or the view controller's view. By default, the property will inherit the tint from the parent view, all the way up to the top level UIWindow of your app.
I had to use both:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil]
forState:UIControlStateNormal];
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor whiteColor]];
And works for me, thank you for everyone!
UINavigationBar *nbar = self.navigationController.navigationBar;
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
//iOS 7
nbar.barTintColor = [UIColor blueColor]; // bar color
//or custom color
//[UIColor colorWithRed:19.0/255.0 green:86.0/255.0 blue:138.0/255.0 alpha:1];
nbar.navigationBar.translucent = NO;
nbar.tintColor = [UIColor blueColor]; //bar button item color
} else {
//ios 4,5,6
nbar.tintColor = [UIColor whiteColor];
//or custom color
//[UIColor colorWithRed:19.0/255.0 green:86.0/255.0 blue:138.0/255.0 alpha:1];
}
Update Swift 3
navigationController?.navigationItem.rightBarButtonItem?.tintColor = UIColor.yellow
navigationController?.navigationBar.tintColor = UIColor.red
navigationController?.navigationBar.barTintColor = UIColor.gray
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blue]
Result:
Just to change the NavigationBar color you can set the tint color like below.
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
In case you're making custom back button basing on UIButton with image of arrow, here is the subclass snippet.
Using it you can either create button in code or just assign class in Interface Builder to any UIButton.
Back Arrow Image will be added automatically and colored with text color.
#interface UIImage (TintColor)
- (UIImage *)imageWithOverlayColor:(UIColor *)color;
#end
#implementation UIImage (TintColor)
- (UIImage *)imageWithOverlayColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
if (UIGraphicsBeginImageContextWithOptions) {
CGFloat imageScale = 1.0f;
if ([self respondsToSelector:#selector(scale)])
imageScale = self.scale;
UIGraphicsBeginImageContextWithOptions(self.size, NO, imageScale);
}
else {
UIGraphicsBeginImageContext(self.size);
}
[self drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
#end
#import "iOS7backButton.h"
#implementation iOS7BackButton
-(void)awakeFromNib
{
[super awakeFromNib];
BOOL is6=([[[UIDevice currentDevice] systemVersion] floatValue] <7);
UIImage *backBtnImage = [[UIImage imageNamed:#"backArrow"] imageWithOverlayColor:self.titleLabel.textColor];
[self setImage:backBtnImage forState:UIControlStateNormal];
[self setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
[self setImageEdgeInsets:UIEdgeInsetsMake(0, is6?0:-10, 0, 0)];
}
+ (UIButton*) buttonWithTitle:(NSString*)btnTitle andTintColor:(UIColor*)color {
BOOL is6=([[[UIDevice currentDevice] systemVersion] floatValue] <7);
UIButton *backBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
UIImage *backBtnImage = [[UIImage imageNamed:#"backArrow"] imageWithOverlayColor:color];
[backBtn setImage:backBtnImage forState:UIControlStateNormal];
[backBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, is6?5:-5, 0, 0)];
[backBtn setImageEdgeInsets:UIEdgeInsetsMake(0, is6?0:-10, 0, 0)];
[backBtn setTitle:btnTitle forState:UIControlStateNormal];
[backBtn setTitleColor:color /*#007aff*/ forState:UIControlStateNormal];
return backBtn;
}
#end
If you want to change only the Back Arrow BUT on the entire app, do this:
[[NSClassFromString(#"_UINavigationBarBackIndicatorView") appearance]
setTintColor:[UIColor colorWithHexString: #"#f00000"]];
In iOS 7, you can put the following line of code inside application:didFinishLaunchingWithOptions: in your AppDelegate.m file:
[[UINavigationBar appearance] setTintColor:myColor];
Set myColor to the color you want the back button to be throughout the entire app. No need to put it in every file.
Swift 2.0: Coloring Navigation Bar & buttons
navigationController?.navigationBar.barTintColor = UIColor.blueColor()
navigationController?.navigationBar.tintColor = UIColor.whiteColor()
navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
In swift 3 , to change UIBarButton back button arrow color
self.navigationController?.navigationBar.tintColor = UIColor.black

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.

Custom transparent UITabBar

I am trying to create an app in which the tab bar transparent (or which looks transparent). For this i'm using part of an image in the view. And set the remaining part as background for tab bar. The problem is the tab bar appears with a darker shade. I'm out of ideas now.
Below is the screen shot
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tabbar_bg.png"]];
self.tabBar.backgroundColor=[UIColor whiteColor];
[self.tabBar insertSubview:imgView atIndex:1];
// [self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"transp.png"]];
// [self.tabBar setSelectedImageTintColor:[UIColor clearColor]];
[[UITabBar appearance] setTintColor:[UIColor clearColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor clearColor]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"transp.png"]];
The above is the code that i've tried out in the viewDidLoad of my custom UITabBarController class. "tabbar_bg.png" is the image used as background for the tab bar and 'transp.png' is a transparent image used as the selectionIndicator image.
Thanks for the help.
Try
[self.tabBar setBackgroundImage:[UIImage new]];
This trick also works for UINavigationBar.
Have you tried creating a subclass of it?
#implementation TabBarInvisible
-(id)init
{
self = [super init];
if (self)
{
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.backgroundImage = nil;
}
return self;
}
-(void)drawRect:(CGRect)rect
{
}
#end

Set NavigationBar background to a solid color

Is there any way I can set the background of the Navigation Bar of the UINavigationController to a solid color?
I know I can change the Tint color, but that still leaves me with the gradient/glass effect.
Any way I can get rid of that, and just have a plain old solid color?
The following code also results in solid color of navigation bar:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]];
I think you have to subclass UINavigationBar and override -(void)drawRect:(CGRect)rect:
UIColor *colorFlat = /* any UIColor*/
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorFlat CGColor]);
CGContextFillRect(context, rect);
I used to override drawRect method and fill color; but after iOS7 upgrade it causes some problems on UINavigationBar. If you write your own drawrect method, even if you call [super drawRect], it changes the bar's dimension and you end up with a navigationBar with 44 pixels height. The status bar is left empty.
To get a solid colored navigationBar, I used an image as background image (any small solid colored image will do since you are stretching it) and added this lines inside the initWithFrame method of the UINavigationBar subclass:
[self setBackgroundColor:[UIColor clearColor]]
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:#"bgimage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5) resizingMode:UIImageResizingModeStretch] forBarMetrics:UIBarMetricsDefault];
The following code worked for me:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
Create a CustomUIViewController that extends UIViewController and override viewDidLoad to something like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 1.0 alpha: 1.0];
}
After that, use your CustomUIViewController in your controllers.
Credits

Resources