zoukankan      html  css  js  c++  java
  • 提取AppDelegate.m中的"RDVTabBarController"第三方框架的方法

    提取这个主要是因为,不想让 “AppDelegate.m” 里面有太多的代码,看起来乱。

    步骤:

    1. 创建一个分类,继承自 AppDelegate 。 

    2. 在类.h中写:

    /**
     *  设置自定义的tabbar
     *
     *  @return 自定义的tabBarController
     */
    - (UIViewController *)setupCustomTabBarController;

    3. 在类.m 中写:

    @implementation AppDelegate (TabBar)
    /**
     *  设置自定义的tabbar
     *
     *  @return 自定义的tabBarController
     */
    - (UIViewController *)setupCustomTabBarController
    {
        // 第一个
        UIViewController *firstViewController = [[UIViewController alloc] init];
        firstViewController.view.backgroundColor = [UIColor redColor];
        UIViewController *firstNavigationController = [[UINavigationController alloc]
                                                       initWithRootViewController:firstViewController];
        
        // 第二个
        UIViewController *secondViewController = [[UIViewController alloc] init];
        secondViewController.view.backgroundColor = [UIColor orangeColor];
        UIViewController *secondNavigationController = [[UINavigationController alloc]
                                                        initWithRootViewController:secondViewController];
        
        // 第三个
        UIViewController *thirdViewController = [[UIViewController alloc] init];
        thirdViewController.view.backgroundColor = [UIColor greenColor];
        UIViewController *thirdNavigationController = [[UINavigationController alloc]
                                                       initWithRootViewController:thirdViewController];
        
        RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
        [tabBarController setViewControllers:@[firstNavigationController, secondNavigationController,
                                               thirdNavigationController]];
        
        [self customizeTabBarForController:tabBarController];
        
        return tabBarController;
    }
    
    - (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
        UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"];
        UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"];
        NSArray *tabBarItemImages = @[@"first", @"second", @"third"];
        
        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++;
        }
    }
    
    - (void)customizeInterface {
        UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
        
        UIImage *backgroundImage = nil;
        NSDictionary *textAttributes = nil;
        
        if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
            backgroundImage = [UIImage imageNamed:@"navigationbar_background_tall"];
            
            textAttributes = @{
                               NSFontAttributeName: [UIFont boldSystemFontOfSize:18],
                               NSForegroundColorAttributeName: [UIColor blackColor],
                               };
        } else {
    #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
            backgroundImage = [UIImage imageNamed:@"navigationbar_background"];
            
            textAttributes = @{
                               UITextAttributeFont: [UIFont boldSystemFontOfSize:18],
                               UITextAttributeTextColor: [UIColor blackColor],
                               UITextAttributeTextShadowColor: [UIColor clearColor],
                               UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
                               };
    #endif
        }
        
        [navigationBarAppearance setBackgroundImage:backgroundImage
                                      forBarMetrics:UIBarMetricsDefault];
        [navigationBarAppearance setTitleTextAttributes:textAttributes];
    }
  • 相关阅读:
    51 Nod 1086 多重背包问题(单调队列优化)
    51 Nod 1086 多重背包问题(二进制优化)
    51 Nod 1085 01背包问题
    poj 2559 Largest Rectangle(单调栈)
    51 Nod 1089 最长回文子串(Manacher算法)
    51 Nod N的阶乘的长度 (斯特林近似)
    51 Nod 1134 最长递增子序列(经典问题回顾)
    51 Nod 1020 逆序排列
    PCA-主成分分析(Principal components analysis)
    Python中cPickle
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5590280.html
Copyright © 2011-2022 走看看