前段时间接触到这个库,感觉还不错!用的也挺多。
效果图如下:
功能简介:
第一个页面:点击后下标显示对应的数字
第二个页面:点击后 隐藏/显示 TabBar
第三个页面:点击后隐藏 TabBar, 并跳转到其他页面;再点击返回按钮时返回,并显示 TabBar.
github 地址:https://github.com/robbdimitrov/RDVTabBarController
- 初始化 ViewController:
UIViewController *firstViewController = [[RDVFirstViewController alloc] init];
UIViewController *firstNavigationController = [[UINavigationController alloc]
initWithRootViewController:firstViewController];
UIViewController *secondViewController = [[RDVSecondViewController alloc] init];
UIViewController *secondNavigationController = [[UINavigationController alloc]
initWithRootViewController:secondViewController];
UIViewController *thirdViewController = [[RDVThirdViewController alloc] init];
UIViewController *thirdNavigationController = [[UINavigationController alloc]
initWithRootViewController:thirdViewController];
RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
[tabBarController setViewControllers:@[firstNavigationController, secondNavigationController,
thirdNavigationController]]; // 添加3个ViewController
self.viewController = tabBarController;
- 页面之间跳转时显示/隐藏 TabBar
// 隐藏 TabBar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}
// 显示 TabBar
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[self rdv_tabBarController]setTabBarHidden:NO animated:YES];
}
- 自定义 TabBar 字体颜色
NSDictionary *selectedFontColor = @{
NSFontAttributeName: [UIFont systemFontOfSize:12],
NSForegroundColorAttributeName: [UIColor redColor],
};
NSDictionary *unSelectedFontColor = @{
NSFontAttributeName: [UIFont systemFontOfSize:12],
NSForegroundColorAttributeName: [UIColor blackColor],
};
item.selectedTitleAttributes = selectedFontColor;
item.unselectedTitleAttributes = unSelectedFontColor;