UITabBar Selected Item Tint Color - ios

I'm working on an UITabBar-Application.
I want to change the selected Item Color with
[[UITabBar appearance] setTintColor:[UIColor redColor]]
This works, until I want to set the Background Color of the TabBar with
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]]
Then the Bar is blue, but the highlighted Items are grey.
[[UITabBar appearance] setBackgroundColor:[UIColor blueColor]]
has no effect.
Any Idea?
Thank you very much!

Try this Code
//Set greenColor for normal State
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
//Set purpleColor for normal State
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor purpleColor] } forState:UIControlStateSelected];
Hope this helps.

Your code, that you've posted, seems to be working. You can do it with images too. Try this:
[tabBarItem1 setImage:[[UIImage imageNamed:#"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:#"home_selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:#"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabbar_selected.png"]];

Related

Change item color in UITabBar iOS

My app has a Tab Bar like the follow:
The Tab Bar must be green and as you can see the icon of the item in Tab Bar are a little hard to see. How I can change the color of the icon in this Tab Bar? I've to use the standard Tab Bar.
Thank you
try this
[[self tabBar] setSelectedImageTintColor:[UIColor greenColor]];
or this
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor purpleColor] } forState:UIControlStateSelected];
Or this
[[self tabBar] setTintColor:[UIColor redColor]];
or this
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor purpleColor]} forState:UIControlStateSelected];
Instead using of icon you can use icon image by using the following code
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
tabBarItem1.selectedImage = [[UIImage imageNamed:#"selectedImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:#"unselectedImage.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.imageInsets= UIEdgeInsetsMake(6, 0, -6, 0);
Try this
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
// set tabbar background image
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tabbar_bg"]];
// remove shadow image of tabbar
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
I would suggest, to change background of UITabbar to some darker colours, instead of green. Just leave the default gray color(Apple masks to gray) for unselected tab. Use below snipped to set selected tab mask color.
[[UITabBar appearance] setTintColor:[UIColor redColor]];
This will avoid confusion to end users whether a tab is selected or in unselected state.

Change tintColor of unselected UITabBarController item title and background image

How can I change the tintColor of an unselected UITabBarItem title and background image iOS 8?
The default color for an unselected state is a light gray color, but it does not show on my darkish shade UITabBar background
I'd like my unselected state to have a color of [UIColor blackColor]
Inside my app delegate didfinishlaunchingwithoptions: I have
UIImage *deselectedE = [[UIImage imageNamed:#"mincraft_axe_green_32.png"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
UIImage *selectedE = [[UIImage imageNamed:#"mincraft_axe_green_32.png"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
e.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Profile" image:deselectedE selectedImage:selectedE];
[[UITabBar appearance] setTintColor:[UIColor blackColor]];
Figured it out!
Use this to change the color of the text:
[[UITabBarItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor greenColor] }
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor blackColor] }
forState:UIControlStateSelected];
And make sure that image rendering mode is set to ORIGINAL for the images
UIImage *deselectedImage = [[UIImage imageNamed:#"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:#"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
In your AppDelegate.m inside of application didFinishLaunchingWithOptions: use the following code:
//unselected icon tint color
[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];
//selected tint color
[[UITabBar appearance] setTintColor:[UIColor greenColor]];
//text tint color
[[UITabBarItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor whiteColor] }
forState:UIControlStateNormal];
//background tint color
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]];
You can also render the image as original from the attributes inspector for the asset file without writing any code
You can also set it up directly in Storyboard... Check my answer here:
How to set UITabBarItem's unselected tint, ***including system items*** (iOS7)
If you're using Storyboard you can also set both Image for Bar Item and Selected Image for Selected Bar Item to get unaltered image in tabBar.
Alternatively in Assets catalog, you can select Render As: Original Image in the attributes of your image (View > Utilities > Show Attributes Inspector or shortcut ⌥⌘4 (Option + Command + 4))

navigationBar.barTintColor always black and not possible to change it

The navigationBar.barTintColor in my app is always black, and there is no way I can change it. I checked all classes and I never set it to black, but I do set it to UIColor clearColor. Still, the bar is black. Any suggestions?
Edit:I found out that the problem is with my [UIColor clearColor], when I change it to any other color it changes the color like it should, but clearColor makes it appear black.
Have a look there
Try modifying the Style and Translucent attributes on the navigation bar (top right in image).
If you are having problems modifying the status bar color, try adding this to your .plist (line below).
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Finally, here's some code you may want.
// Status bar color
[[UIApplication sharedApplication] setStatusBarStyle:yourStyle];
// Navigation bars color
[UINavigationBar appearance].barStyle = yourStyle;
[UINavigationBar appearance].barTintColor = [UIColor yourColor];
// Navigation bars items color
[UINavigationBar appearance].tintColor = [UIColor yourColor];
If its IOS7 try the code below
[[UINavigationBar appearance]setBarTintColor: [<Specify the UIColor you want>];
In IOS6 try this
[[UINavigationBar appearance] setTintColor: [<Specify the UIColor you want>];
Edit:
I think you have given
self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
This will give black color. If you want any specific tint color, it must be specifed after clearing
self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
self.navigationController.navigationBar.barTintColor = [UIColor <specify your color>];
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
#{
UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeTextShadowColor: [UIColor clearColor],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],UITextAttributeFont: [UIFont fontWithName:#"ArialMT" size:18.0f]
}];
CGFloat verticalOffset = -4;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
else
{
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// Uncomment to change the color of back button
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Uncomment to assign a custom backgroung image
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg_ios7.png"] forBarMetrics:UIBarMetricsDefault];
// Uncomment to change the back indicator image
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#""]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#""]];
// Uncomment to change the font style of the title
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:#"ArialMT" size:18.0], NSFontAttributeName, nil]];
CGFloat verticalOffset = -4;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
In iOS 7 try:
[self.navigationController.navigationBar setTranslucent:NO];

In iOS 7, how do i change the color of the "More" tab bar item?

I'm able to set finished selected and unselected images for all the other tabs, but not for the "More" item which is special.
How can i do this?
Here is the current code:
[[UITabBar appearance] setTintColor:contrastColor];
[[UITabBarItem appearance] setTitleTextAttributes:#{UITextAttributeTextColor: contrastColor, UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)]} forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:#{UITextAttributeTextColor: contrastColor, UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)]} forState:UIControlStateNormal];
contrastColor is white and delivered from our backend system.
I don't know if this is an option for you or not, but you can try find a "More" image similar to the one you are using instead of using Apple's, which I am assuming you are using; if not just ignore me.
Then just do this:
UITabBarItem *tabBarItem4 = [[tabViewController.tabBar items] objectAtIndex:3];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:#"tabbar-more-selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tabbar-more-normal"]];
Have you tried with this?
tabBarController.tabBar.barTintColor = yourBarColor;
tabBarController.tabBar.tintColor = yourSelectedIconAndTextColor;
And for different states:
[[UITabBarItem appearance] setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:yourFontName size:yourFontSize], NSForegroundColorAttributeName: yourSelectedIconAndTextColor} forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:#{NSFontAttributeName : [UIFont fontWithName:yourFontName size:yourFontSize], NSForegroundColorAttributeName:[UIColor defaultColor]} forState:UIControlStateNormal];
Hope it helps!

How to customize UINavigationBar in IOS5

In IOS5, I do not yet know how to customize UINavigationBar.
My code is like this:
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithWhite:0.5f alpha:1.0]];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor],UITextAttributeTextColor
,[UIColor blackColor], UITextAttributeTextShadowColor
,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset
,[UIFont fontWithName:#"Arial" size:20.0],UITextAttributeFont
, nil]];
// Customize UIBarButtonItems
UIImage *gradientImage44 = [[UIImage imageNamed: #"title__bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor
,[UIColor whiteColor], UITextAttributeTextShadowColor
,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset
,[UIFont fontWithName:#"Arial" size:14.0],UITextAttributeFont
, nil] forState:UIControlStateNormal];
// Customize back button items differently
UIImage *buttonBack30 = [[UIImage imageNamed:#"bn_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
This pic is UINavigationViewController used in PopoverView.
This pic is UINavigationViewController opened by Modal.
As you see, I set background-image, nevertheless NavigationBar's border is different.
Is this a problem about PopoverView?
I do not know What I'd missed.
Please tell me your advice. Thanks!!! and Happy new year!!!
Goto AppDelegate.m and paste the code under
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Set the status bar to black color.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque
animated:NO];
Change #"menubar.png" to the file name of your image.
UIImage *navBar = [UIImage imageNamed:#"menubar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBar
forBarMetrics:UIBarMetricsDefault];
Have a look at this: UINavigationBar Apple developer reference

Resources