How can i specify the tint of images when a tab is selected and unselected?
I have tried this but it doesnt work:
[[UITabBar appearance] setTintColor:[UI
if you do not have many viewcontrollers. Here is my way to do it.
In your delegate method just place your tabbar bg Image. And set the UIImageView
Create 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 every ViewController in tabbar add
-(void)viewWillAppear:(BOOL)animated
delegate method and in this method. You can change the Imageviews 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 costumize tabImageArray in every View controller. Then you can use it.
I works on iOS 7 as well.