UITabBar hue in iOS 7

How can I specify the hue of images when a tab is selected and not selected?

I tried this, but it does not work:

[[UITabBar appearance] setTintColor:[UIColor redColor]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; 

In this case, the selected hue will be red (not green) and unselected shade of gray (not red).

+13
ios objective-c iphone uikit
Oct 07 '13 at 17:29
source share
4 answers

You can set the color of the shades for the selected and unselected buttons of the tab bar, for example:

 [[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; 

The first line sets the unselected color — red in this example — by setting tintColor UIView when it is contained in the tab bar. Please note that this only sets the hue color of the unselected image - it does not change the color of the text below it.

The second line sets the color of the highlighted hue of the selected hue to green.

+25
Mar 12 '14 at 14:29
source share

Are you using a template version of your images?

Instead of setting up images using [UIImage imageNamed: @"MyImage"] install them using [[UIImage imageNamed: @"MyImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate] .

This setting along with your code should solve this problem.

0
Oct 07 '13 at 19:12
source share

You should use the new image rendering modes introduced in iOS 7 ( UIImageRenderingModeAlwaysOriginal and UIImageRenderingModeAlwaysTemplate ), see my answer to a similar question :

Hope this helps

0
Oct 27 '13 at 18:11
source share

if you do not have a large number of view controllers. Here is my way to do it.

In the delegate method, just place your bg Image tab. And install UIImageView

Create a UITabbar intance in AppDelegate.h

 @property (nonatomic,retain) UITabBar *tabbar; 

AND

 @synthesize tabbar; UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; tabbar = [tabBarController tabBar]; [tabbar setBackgroundImage:[UIImage imageNamed:@"tabbarBg.png"]]; NSArray *tabImageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"tab1Hover.png"], [UIImage imageNamed:@"tab2.png"], [UIImage imageNamed:@"tab3.png"], [UIImage imageNamed:@"tab4.png"], [UIImage imageNamed:@"tab5.png"], nil]; for (int i = 0; i<5; i++) { UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(20+i*60+i*3.5, 10, 25, 21)]; [image setContentMode:UIViewContentModeScaleAspectFit]; [image setImage:[tabImageArray objectAtIndex:i]]; [image setTag:10+i]; [tabbar addSubview:image]; } 

Then each ViewController in the tab adds

 -(void)viewWillAppear:(BOOL)animated 

delegate the method to this method as well. You can change the images as shown below.

 -(void)viewWillAppear:(BOOL)animated{ AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; UITabBarController *tabBarController = (UITabBarController *)appDelegate.window.rootViewController; NSArray *tabImageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"tab1Hover.png"], [UIImage imageNamed:@"tab2.png"], [UIImage imageNamed:@"tab3.png"], [UIImage imageNamed:@"tab4.png"], [UIImage imageNamed:@"tab5.png"], nil]; for (int i = 0; i<5; i++) { UIImageView *image = (UIImageView*)[tabbar viewWithTag:10+i]; [image setImage:[tabImageArray objectAtIndex:i]]; } } 

So, just bypass the tabImageArray in each View controller. Then you can use it.

I also work on iOS 7.

-one
Oct 08 '13 at
source share



All Articles