OC 自定义 UITabBarController
创建 UITabBarController 子类
通过一下代码可简单自定义 UITabBarController
+ (void)initialize {
UITabBar *tabBar = [UITabBar appearance];
// 设置 UITabBar 背景
[tabBar setBackgroundColor:[UIColor whiteColor]];
[tabBar setTintColor:[UIColor colorWithRed:234/255.0 green:57/255.0 blue:57/255.0 alpha:1]];
[tabBar setBarTintColor:[UIColor whiteColor]];
设置UITabBarItem字体样式
UITabBarItem *barItem = [UITabBarItem appearance];
// UIImage *image = barItem.image;
// barItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionary];
itemAttrs[NSForegroundColorAttributeName] =[UIColor colorWithRed:234/255.0 green:57/255.0 blue:57/255.0 alpha:1];
[barItem setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
[barItem setTitleTextAttributes:itemAttrs forState:UIControlStateHighlighted];
}
#iOS 默认 UITabBarItem 未选中图标颜色为灰色, 通过以下代码可设置为图片本身的颜色
- (void)awakeFromNib {
[super awakeFromNib];
// 修改未选中默认图标样式
for (UITabBarItem *item in self.tabBar.items) {
item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//UIImageRenderingModeAlwaysOriginal// 原版样式
}
}