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];
    }
  • 相关阅读:
    负margin在页面布局中的应用
    2018-05-04 圣杯布局 and 双飞翼布局,display:flex
    vue 动态加载图片路径报错解决方法
    vue 带参数的跳转-完成一个功能之后 之后需要深思,否则还会忘记
    vue项目打包后打开空白解决办法
    css 居中方法
    vue 不用npm下载安装包 该如何引用js
    安装WAMP 及 修改MYSQL用户名 、 密码
    Python 软件开发目录规范
    Python 1-3区分Python文件的两种用途和模块的搜索路径
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5590280.html
Copyright © 2011-2022 走看看