I like to have a custom selected image when a user selects an item on the tab bar, by default it selects as blue like but would like to have a green color instead. something like below any thoughts?
+2
A:
This is not officially supported in the SDK. You may be able to probe and adjust the tab's views at runtime, but you risk a rejection from Apple.
Edit: For completeness, I should mention that your other option is to roll your own UITabBar.
Justin
2010-08-11 19:12:38
A:
Just add some custom views (using insertSubview:atIndex:) when the UITabBarController-delegate-methods are called.
Example:
– (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[tabBarController.tabBar insertSubview:someView atIndex:someIndex];
}
You can try changing someIndex
yourself till you have the result you want.
Tim van Elsloo
2010-08-11 20:13:33
+2
A:
Just found my solution. Basically, I subclassed UITabItem and set this in the navigation controller:
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
CustomTabBarItem *tabItem = [[CustomTabBarItem alloc] initWithTitle:@"Events" image:[UIImage imageNamed:@"tabIcon.png"] tag:0];
tabItem.customHighlightedImage=[UIImage imageNamed:@"tabIconSelected.png"];
self.tabBarItem = tabItem;
[tabItem release];
tabItem=nil;
}
Here's what the CustomTabBarItem class looks like:
@interface CustomTabBarItem : UITabBarItem
{
UIImage *customHighlightedImage;
}
@property (nonatomic, retain) UIImage *customHighlightedImage;
@end
implementation:
#import "CustomTabBarItem.h
@implementation CustomTabBarItem
@synthesize customHighlightedImage;
- (void)dealloc {
[customHighlightedImage release];
customHighlightedImage=nil;
[super dealloc];
}
-(UIImage *)selectedImage {
return self.customHighlightedImage;
}
@end
Frank
2010-09-21 16:59:03
what is customHighlightedImage? What did you put in the CustomTabBarItem class?
alku83
2010-10-29 04:07:16
just added more details on what CustomTabBarItem looks like
Frank
2010-10-29 17:36:19