测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
Released最新发布 | 2015年11月 |
由 Shilong Li 维护。
将 RDVTabBarController
目录中的项目添加到您的项目中。如果未启用 ARC,您需要在 .m
源文件上设置 -fobjc-arc
编译器标志。
初始化类似于 UITabBarController
。创建一个 tabBarController
实例,并初始化其 viewControllers
。
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]];
self.viewController = tabBarController;
每个 RDVTabBarItem
都有 selectedBackground
、unselectedBackground
以及相应的图标属性:selectedImage
和 unselectedImage
。
UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"];
UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"];
NSArray *tabBarItemImages = @[@"first", @"second", @"third"];
RDVTabBar *tabBar = [tabBarController tabBar];
[tabBar setFrame:CGRectMake(CGRectGetMinX(tabBar.frame), CGRectGetMinY(tabBar.frame), CGRectGetWidth(tabBar.frame), 63)];
NSInteger index = 0;
for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
[item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];
UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",
[tabBarItemImages objectAtIndex:index]]];
UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",
[tabBarItemImages objectAtIndex:index]]];
[item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
index++;
}
RDVTabBar
有一个 translucent
属性,它确定该属性将如何被处理。
RDVTabBar *tabBar = tabBarController.tabBar;
// After the tabBarController initialization
tabBar.translucent = YES;
// Customize the tabBar background
tabBar.backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0
green:245/255.0
blue:245/255.0
alpha:0.9]];
// Inside the tabbed viewControllers
- (void)viewDidLoad {
[super viewDidLoad];
...
if (self.rdv_tabBarController.tabBar.translucent) {
CGFloat tabBarHeight = CGRectGetHeight(self.rdv_tabBarController.tabBar.frame);
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, tabBarHeight, 0);
self.tableView.contentInset = insets;
self.tableView.scrollIndicatorInsets = insets;
}
}
RDVTabBarController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。