RDVTabBarController 1.3.0

RDVTabBarController 1.3.0

测试已测试
语言 Obj-CObjective C
许可证 MIT
发布最后发布2019年10月

Robert Dimitrov维护。



  • Robert Dimitrov

RDVTabBarController

iPad screenshot

iPhone screenshot

  • 支持 iPad 和 iPhone
  • 支持横竖屏
  • 可在 UINavigationController 内使用
  • 可定制徽章

安装

CocoaPods

如果您使用 CocoaPods,只需在 Podfile 中添加 pod 'RDVTabBarController' 即可。

拖放

RDVTabBarController 目录中的项添加到您的项目中。如果您未启用 ARC,需要将 -fobjc-arc 编译器标志设置在 .m 源文件上。

示例用法

初始化RDVTabBarController

初始化方式与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;

自定义RDVTabBarController

每个RDVTabBarItem都拥有selectedBackgroundunselectedBackground以及对应图标的属性:selectedImageunselectedImage

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;
    }
}

要求

  • ARC
  • iOS 8.0或更高版本
  • Xcode 11

联系

Robert Dimitrov
@robbdimitrov

许可证

RDVTabBarController 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。