• [翻译] RDVTabBarController


    RDVTabBarController

    https://github.com/robbdimitrov/RDVTabBarController

    效果:

    • Supports iPad and iPhone 支持iPad与iPhone
    • Supports landscape and portrait orientations 支持横竖屏切换动画
    • Can be used inside UINavigationController 可以用在UINavigationController里面
    • Customizable badges 可定制的提示标签

    Installation 安装

    CocoaPods - cocoaPods

    If you're using CocoaPods, simply add pod 'RDVTabBarController' to your Podfile.

    如果你使用了CocoaPods,简单的pod ‘RDVTabBarController’ 到你的Podfile文件中就行了。

    Drag & Drop - 拖到项目当中

    Add the items from RDVTabBarController directory to your project. If you don't have ARC enabled, you will need to set a -fobjc-arc compiler flag on the .m source files.

    直接将RDVTabBarController文件夹拖到你的项目当中。如果你的项目是MRC的,你需要在.m文件里面设置-fobjc-arc编译标签。

    Example Usage - 使用示例

    Initialize RDVTabBarController

    初始化RDVTabBarController

    The initialization is similar to the one for UITabBarController. Create an instance of the tabBarController and initialize its viewControllers.

    初始化方法与UITabBarController类似,创建一个tabBarController的实例以及初始化控制器。

    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;

    Customize RDVTabBarController - 定制RDVTabBarController

    Each RDVTabBarItem has selectedBackgroundunselectedBackground and corresponding properties for the icons: selectedImage and unselectedImage.

    每一个RDVTabBarItem都有选择被背景与未选择的背景,或者是对应于选择的图片与未选择的图片。

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

    Make the tab bar translucent - 可以让tab bar变得半透明

    RDVTabBar has translucent property which determines how it is going to be handled.

    RDVTabBar有着半透明色这个属性,他决定着怎么个透明方式。

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

    Requirements - 需要的环境

    • ARC 
    • iOS 5.0 or later
    • Xcode 5

     

    Contact

    Robert Dimitrov
    @robbdimitrov

  • 相关阅读:
    洛谷1098 字符串的展开 解题报告
    洛谷1086 花生采摘 解题报告
    洛谷1125 笨小猴 解题报告
    洛谷1056 排座椅 解题报告
    洛谷1067 多项式输出 解题报告
    洛谷1003 铺地毯 解题报告
    JS在不同js文件中互相调用
    JS鼠标滚轮事件
    JS闭包
    PHP中header('content-type:text/html;charset="utf-8')和error_reporting()的作用
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4166416.html
Copyright © 2020-2023  润新知