First Add New Class in Project:
//======== .h file ==================
#import <Foundation/Foundation.h>
@interface CustomTabBarItem : UITabBarItem
{
UIImage *customHighlightedImage;
UIImage *customStdImage;
}
@property (nonatomic, retain) UIImage *customHighlightedImage;
@property (nonatomic, retain) UIImage *customStdImage;
@end
//====== implementation file .m ========
#import "CustomTabBarItem.h"
@implementation CustomTabBarItem
@synthesize customHighlightedImage;
@synthesize customStdImage;
- (void) dealloc
{
[customHighlightedImage release]; customHighlightedImage=nil;
[customStdImage release]; customStdImage=nil;
[super dealloc];
}
-(UIImage *) selectedImage
{
return self.customHighlightedImage;
}
-(UIImage *) unselectedImage
{
return self.customStdImage;
}
@end
//========= And then Use it on your ViewController ==============
#import "CustomTabBarItem.h"
- (void)awakeFromNib {
CustomTabBarItem *tabItem = [[CustomTabBarItem alloc]
initWithTitle:@"" image:nil tag:0];
tabItem.customHighlightedImage=[UIImage imageNamed:@"but-home-active"];
tabItem.customStdImage=[UIImage imageNamed:@"but-home"];
UIEdgeInsets titleInsets = UIEdgeInsetsMake(2.0, 0.0, -5.0, 0.0);
tabItem.imageInsets = titleInsets;
self.tabBarItem=tabItem;
[tabItem release];
tabItem=nil;
[super awakeFromNib];
}
//======== .h file ==================
#import <Foundation/Foundation.h>
@interface CustomTabBarItem : UITabBarItem
{
UIImage *customHighlightedImage;
UIImage *customStdImage;
}
@property (nonatomic, retain) UIImage *customHighlightedImage;
@property (nonatomic, retain) UIImage *customStdImage;
@end
//====== implementation file .m ========
#import "CustomTabBarItem.h"
@implementation CustomTabBarItem
@synthesize customHighlightedImage;
@synthesize customStdImage;
- (void) dealloc
{
[customHighlightedImage release]; customHighlightedImage=nil;
[customStdImage release]; customStdImage=nil;
[super dealloc];
}
-(UIImage *) selectedImage
{
return self.customHighlightedImage;
}
-(UIImage *) unselectedImage
{
return self.customStdImage;
}
@end
//========= And then Use it on your ViewController ==============
#import "CustomTabBarItem.h"
- (void)awakeFromNib {
CustomTabBarItem *tabItem = [[CustomTabBarItem alloc]
initWithTitle:@"" image:nil tag:0];
tabItem.customHighlightedImage=[UIImage imageNamed:@"but-home-active"];
tabItem.customStdImage=[UIImage imageNamed:@"but-home"];
UIEdgeInsets titleInsets = UIEdgeInsetsMake(2.0, 0.0, -5.0, 0.0);
tabItem.imageInsets = titleInsets;
self.tabBarItem=tabItem;
[tabItem release];
tabItem=nil;
[super awakeFromNib];
}