UIKit - UITabBarController
2020-04-20 本文已影响0人
ienos
设置 TabBarItem 的文字属性
NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
[self.tabBarItem setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];\
替换 UITabBarController 的 TabBar
[self setValue: [[XMGTabBar alloc]init ] forKeyPath:”tabBar”];
设置 TabBarItem 文字偏移
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -3)];
hidesBottomBarWhenPushed Bug
// 如果掉了 self.tabBarcontroller.tabBar.hidden = YES , 且在 push 出新的控制器时设置了 hidesBottomBarWhenPushed = YES,
// pop 回来之后 tabBar 会显示,下面👇重写方法防止该情况发生
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (viewController.hidesBottomBarWhenPushed && self.tabBarController) {
if (self.tabBarController.tabBar.hidden) {
viewController.hidesBottomBarWhenPushed = NO;
}
}
[super pushViewController:viewController animated:animated];
}