3
votes

Im trying to implement custom colors in UITabBar.But i dont know what the problem is.I placed an image on 1 tabBar.when the tabBar is active,i want one image and when tabBar is inactive,i want another image to be displayed on the same tabBar.How? Also guide me that the image is placed at the center of the tabBar.Please tell me the Xcode for this implementation-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
for(UIView *view in self.tabBarController.tabBar.subviews) {
if([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
}

[self.tabBarController.tabBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon-a.png"]] autorelease] atIndex:0];  

}

  • (void)viewWillDisappear:(BOOL)animated { //[superviewWillDisappear:animated]; for(UIView *view in self.tabBarController.tabBar.subviews) {
    if([view isKindOfClass:[UIImageView class]]) {
    [view removeFromSuperview];
    }
    }

    [self.tabBarController.tabBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon-c.png"]] autorelease] atIndex:0];
    }
    I used these methods to implement my task.But i coudn't get the solution.Please help me

1

1 Answers

2
votes

You may refer the source code available in the following link, Hope it will fix your problem.. https://github.com/rumex/RXCustomTabBar