我自定义 UITabbar 的方式在 IOS 5 和 IOS 6 中运行良好,但在 IOS7 中,Tabbar 没有显示任何图像。
IOS6结果:
IOS7结果:
在做了一些研究后,我尝试修复现有代码,但没有成功。这是我在 ios6 中运行良好的代码
#import <Foundation/Foundation.h>
@interface CustomTabBarItem : UITabBarItem
{
UIImage *selectedImg;
UIImage *unSelectedImg;
}
@property (nonatomic, retain) UIImage *selectedImg;
@property (nonatomic, retain) UIImage *unSelectedImg;
@end
#import "CustomTabBarItem.h"
@implementation CustomTabBarItem
@synthesize selectedImg;
@synthesize unSelectedImg;
-(UIImage *) selectedImage
{
return self.selectedImg;
}
-(UIImage *) unselectedImage
{
return self.unSelectedImg;
}
@end
现在在 appDelegate
self.tabBarController.delegate = self;
self.tabBarController.tabBar.frame = CGRectMake(0, self.tabBarController.tabBar.frame.origin.y, self.tabBarController.tabBar.frame.size.width, 49);
for(int i=1;i<=4;i++)
{
CustomTabBarItem *tabItem = [[CustomTabBarItem alloc] initWithTitle:@"" image:nil tag:0];
tabItem.selectedImg=[UIImage imageNamed:[NSString stringWithFormat:@"tab_bar-%d_over_%@.png",i,deviceType]];
tabItem.unSelectedImg=[UIImage imageNamed:[NSString stringWithFormat:@"tab_bar-%d_%@.png",i,deviceType]];
UIEdgeInsets titleInsets = UIEdgeInsetsMake(6.0, 0.0, -6.0, 0.0);
tabItem.imageInsets = titleInsets;
[[self.tabBarController.viewControllers objectAtIndex:i-1] setTabBarItem:tabItem];
[tabItem release];
}
上面的代码在 IOS6 中运行良好,在做了一些研究后,我对 IOS7 做了一些更改
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
CustomTabBarItem *tabItem = [[CustomTabBarItem alloc] initWithTitle:@"" image:nil tag:0];
tabItem.image = [[UIImage imageNamed:[NSString stringWithFormat:@"tab_bar-%d_over_%@.png",i,deviceType]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"tab_bar-%d_%@.png",i,deviceType]];
但结果仍然相同,任何帮助将不胜感激。