2 回答
TA贡献1998条经验 获得超6个赞
写一个控制器继承自UITabBarController,
在该控制器的ViewDidLoad方法中加入如下代码
// tabBarItem的图片名称
NSArray *images = @[@"tabBarItem_allTest_normal.png",@"tabBarItem_allTest_selected.png",@"tabBarItem_oneStation_normal.png",@"tabBarItem_oneStation_selected.png",@"tabBarItem_testResult_normal.png",@"tabBarItem_testResult_selected.png",@"tabBarItem_userCenter_normal.png",@"tabBarItem_userCenter_selected.png"];
for(int i= 0;i< 8;){
// 分别给tabBarItem设置图片,图片模式为源图片
UITabBarItem *item = [self.tabBar.items objectAtIndex:i/2];
UIImage *normalImage = [UIImage imageNamed:images[i+1]];
normalImage = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectImage = [UIImage imageNamed:images[i]];
selectImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[item setFinishedSelectedImage:normalImage
withFinishedUnselectedImage:selectImage];
i+=2;
}
// 设置tabbar的选中和未选中的字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName:[UIColor lightGrayColor]
} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName:[UIColor lightGrayColor]
} forState:UIControlStateSelected];
- 2 回答
- 0 关注
- 793 浏览
添加回答
举报