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];
    }
  • 相关阅读:
    1539. Kth Missing Positive Number (E)
    0082. Remove Duplicates from Sorted List II (M)
    0526. Beautiful Arrangement (M)
    解决mac电脑耳机/外放突然无声音
    利用蒙特卡洛方法实现21点问题的最优解(内含python源码)
    浅析机器视觉在医疗影像处理中的应用
    基于最近邻法手写数字识别(内附python源码)
    最新版 | 2020李沐《动手学深度学习》中文版pdf重磅开源!
    干货收藏!639页《深度学习:Deep Learning》图文并茂课程PPT
    22课时、19大主题,CS 231n进阶版课程视频上线!
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5590280.html
Copyright © 2011-2022 走看看