RDVTabBarController

RDVTabBarController这个库写得相当不错,所以今天就简单介绍下它的基本使用,看里面可以清楚的知道代码规范的重要性,这个库的使用方法和官方的相识

下载地址:https://github.com/robbdimitrov/RDVTabBarController

首先写过控制器继承  RDVTabBarController,

AppDelegate里面的不多说

例如

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     
RDVViewController *rootViewController = [[RDVViewController alloc] init];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];

然后在

RDVViewController.m文件里

为了防止tabbar的双点击事件,设置代理,添加标示,用在点击事件

要设置tabbaritem的字体和图片,需导入文件

import "RDVTabBarItem.h"

#import "RDVViewController.h"
#import "ViewController.h"
#import "RDVTabBarItem.h"

@interface RDVViewController ()

@end

@implementation RDVViewController

- (void)viewDidLoad {
     [super viewDidLoad];
     
     ViewController *homeView=[[ViewController alloc]init];
     UINavigationController *NAV1 = [[UINavigationController alloc] initWithRootViewController:homeView];
     
     ViewController *View=[[ViewController alloc]init];
     UINavigationController *NAV2 = [[UINavigationController alloc] initWithRootViewController:View];
     
     ViewController *home=[[ViewController alloc]init];
    UINavigationController *NAV3 = [[UINavigationController alloc] initWithRootViewController:home];
     
     self.viewControllers = @[NAV1,NAV2,NAV3];
     [self customizeTabBarForController:self];

 }
 
 - (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    
     NSArray *tabBarItemImages = @[@"首页select", @"首页select",@"首页select"];
     
     NSInteger index = 0;
     for (RDVTabBarItem *tabberItem in [[tabBarController tabBar] items]) {
         
         tabberItem.title = [NSString stringWithFormat:@"%ld",index+1];
         
         NSDictionary *tabBarTitleUnselectedDic = @{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};
        NSDictionary *tabBarTitleSelectedDic = @{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};
         //修改tabberItem的title颜色
         tabberItem.selectedTitleAttributes = tabBarTitleSelectedDic;
         tabberItem.unselectedTitleAttributes = tabBarTitleUnselectedDic;

         UIImage *selectedimage = [UIImage imageNamed:@"首页"];
         UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@",
                                                         [tabBarItemImages objectAtIndex:index]]];
         //设置tabberItem的选中和未选中图片
         [tabberItem setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
        
         index++;
     }
 }

你可能感兴趣的:(RDVTabBarController)