有没有办法为UITabBarItem使用自定义选定的图像? [英] Is there a way to use a custom selected image for UITabBarItem?
本文介绍了有没有办法为UITabBarItem使用自定义选定的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户选择标签栏上的项目时,我喜欢自定义选择的图像,默认情况下,它选择为蓝色,但希望使用绿色。类似下面的任何想法?
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?
alt text http:// www .freeimagehosting.net / uploads / 11a2137011.png
推荐答案
刚刚找到我的解决方案。基本上,我将UITabItem子类化并在导航控制器中设置:
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;
}
以下是CustomTabBarItem类的样子:
Here's what the CustomTabBarItem class looks like:
@interface CustomTabBarItem : UITabBarItem
{
UIImage *customHighlightedImage;
}
@property (nonatomic, retain) UIImage *customHighlightedImage;
@end
实施:
#import "CustomTabBarItem.h
@implementation CustomTabBarItem
@synthesize customHighlightedImage;
- (void)dealloc {
[customHighlightedImage release];
customHighlightedImage=nil;
[super dealloc];
}
-(UIImage *)selectedImage {
return self.customHighlightedImage;
}
@end
这篇关于有没有办法为UITabBarItem使用自定义选定的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文