RDVTabBarController-gc 1.1.9

RDVTabBarController-gc 1.1.9

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新发布2015年11月

Shilong Li 维护。



  • gooc

RDVTabBarController

iPad screenshot

iPhone screenshot

  • 支持 iPad 和 iPhone
  • 支持横屏和竖屏方向
  • 可在 UINavigationController 内使用
  • 可自定义徽章

安装

拖放

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

示例用法

初始化 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 5.0 或更高版本
  • Xcode 5

联系

Robert Dimitrov
@robbdimitrov

许可证

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