当前位置: 首页 > news >正文

RDVTabBarController--可自由定制的iOS底部导航控件

为什么80%的码农都做不了架构师?>>>   hot3.png

  • RDVTabBarController:一个十分完善的tabBarController,可以自定义角标个数,爽的停不下来。
  • RDVTabBarController地址:<a href ="https://github.com/robbdimitrov/RDVTabBarController">RDVTabBarController</a>
  • Demo地址:<a href ="https://github.com/sauchye/SYTipsDemo">欢迎Star</a>

说明

  • 此教程是旨在让你快速入手,如需更加深层次的了解,请直接RDVTabBarController地址分析即可;

使用

pod 'RDVTabBarController'

建议直接CocoaPods管理,对CocoaPods有兴趣的童鞋可以戳<a href="http://code4app.com/article/cocoapods-install-usage">cocoapods-install-usage</a>

结构

RDVTabBar 
@interface RDVTabBar : UIView
RDVTabBarController
@interface RDVTabBarController : UIViewController 
RDVTabBarItem
@interface RDVTabBarItem : UIControl

RDVTabBarController Example Usage其实已经很详细了,接下来看初始化

 //VString宏定义,为了就是更好的国际化语言,适配多语言,刚好此Demo也国际化了,可以参看https://github.com/sauchye/dev_notes/issues/4 
#define VString(x)      NSLocalizedString(x, nil)
- (void)setupViewControllers{
    SYFirstViewController *firstVC = [[SYFirstViewController alloc] init];
    SYSecondViewController *secondVC = [[SYSecondViewController alloc] init];
    SYThirdViewController *thirdVC = [[SYThirdViewController alloc] init];
    firstVC.title = VString(@"Home");
    secondVC.title = VString(@"Found");
    thirdVC.title = VString(@"Me");
    self.firstNav = [[SYBaseNavigationController alloc] initWithRootViewController:firstVC];
    self.secondNav = [[SYBaseNavigationController alloc] initWithRootViewController:secondVC];
    self.thirdNav = [[SYBaseNavigationController alloc] initWithRootViewController:thirdVC];
    [self setViewControllers:@[self.firstNav, self.secondNav, self.thirdNav]];
    [self customizeTabBarForController];
}
- (void)customizeTabBarForController{

    //tabbar 背景图片 tabbar_background
    UIImage *backgroundImage = [UIImage imageNamed:@"tabbar_background"];
    //选项卡图片
    NSArray *tabBarItemImages;
  	//这里添加tabBar icon图片
    //= @[VString(@"First"), VString(@"Second"),VString(@"Third")];

    NSArray *tabBarItemTitles = @[VString(@"Home"), VString(@"Found"), VString(@"Me")];
    NSInteger index = 0;
    for (RDVTabBarItem *item in [[self tabBar] items])
    {
        item.titlePositionAdjustment = UIOffsetMake(0, 2.0);
        [item setBackgroundSelectedImage:backgroundImage withUnselectedImage:backgroundImage];
        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];

        [item setTitle:[tabBarItemTitles objectAtIndex:index]];
        item.selectedTitleAttributes = @{
                                         NSFontAttributeName: [UIFont boldSystemFontOfSize:12],
                                         NSForegroundColorAttributeName:kNAVIGATION_BAR_COLOR,
                                         };
        item.unselectedTitleAttributes = @{
                                           NSFontAttributeName: [UIFont boldSystemFontOfSize:12],
                                           NSForegroundColorAttributeName:RGB(217, 217, 217),
                                           };

        [item setTitle:[tabBarItemTitles objectAtIndex:index]];
        index++;

    }
}

这样你的tabBar基本搭建好了,但是还需要完善一些,比如,角标设置,push隐藏等。

  • Push隐藏tabBar,你只需要这样即可

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    }
    
  • 设置角标数

     [[self rdv_tabBarItem] setBadgeValue:@"3"];
    
  • RDVTabBarControllerDelegate,相信你看就会明白,好的方法命名很重要啊~

    /**
     * Asks the delegate whether the specified view controller should be made active.
     */
    - (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
    
    /**
     * Tells the delegate that the user selected an item in the tab bar.
     */
    - (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    
  • 还有需要多等待你去发现...


结语

RDVTabBarController是一个很棒的第三方tabBarController,值得我们学习和思考。

  • 相比传统第三方,你会发现可以很好的定制角标,这是极好的,当然你也可以自定义;
  • 但是不能定义中间凸起的tabBar,好早之前去哪儿就是中间凸起一个tabBar,不过现在去哪儿也改成传统的tabBar了;

本文,由我们 iOS122 的小伙伴 @Sauchye​供稿,更多讨论,参见: http://www.ios122.com/tag/rdvtabbarcontroller/

转载于:https://my.oschina.net/ios122/blog/515267

相关文章:

  • 智能园区报修系统可行性分析
  • 堆排序学习笔记及堆排序算法的python实现
  • Golang 并发简介
  • Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
  • url 中文传参 乱码问题
  • Android签名机制
  • libsuperuser简介
  • Linux缓存释放
  • 从头开始编写项目Makefile(八):型号规则
  • STM32 ~ CH340在STM32实现一键下载电路
  • Python gui开发之tkinter
  • Java连接Oracle数据库简单实例
  • Unity3d之Http通讯GET方法和POST方法
  • 环信首席架构师梁宇鹏谈架构、管理及成长
  • IOS TableView 去除点击后产生的灰色背景
  • php的引用
  • [nginx文档翻译系列] 控制nginx
  • 《Java编程思想》读书笔记-对象导论
  • android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
  • Android优雅地处理按钮重复点击
  • Docker 笔记(2):Dockerfile
  • EOS是什么
  • Java应用性能调优
  • js对象的深浅拷贝
  • js如何打印object对象
  • Koa2 之文件上传下载
  • 爱情 北京女病人
  • 成为一名优秀的Developer的书单
  • 前嗅ForeSpider中数据浏览界面介绍
  • 提升用户体验的利器——使用Vue-Occupy实现占位效果
  • 微信公众号开发小记——5.python微信红包
  • 小程序 setData 学问多
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 译自由幺半群
  • 终端用户监控:真实用户监控还是模拟监控?
  • 2017年360最后一道编程题
  • 函数计算新功能-----支持C#函数
  • ​批处理文件中的errorlevel用法
  • #我与Java虚拟机的故事#连载13:有这本书就够了
  • #预处理和函数的对比以及条件编译
  • (1)SpringCloud 整合Python
  • (react踩过的坑)Antd Select(设置了labelInValue)在FormItem中initialValue的问题
  • (二) Windows 下 Sublime Text 3 安装离线插件 Anaconda
  • (每日持续更新)jdk api之FileFilter基础、应用、实战
  • (算法设计与分析)第一章算法概述-习题
  • (心得)获取一个数二进制序列中所有的偶数位和奇数位, 分别输出二进制序列。
  • (一)基于IDEA的JAVA基础10
  • (原創) 是否该学PetShop将Model和BLL分开? (.NET) (N-Tier) (PetShop) (OO)
  • (转贴)用VML开发工作流设计器 UCML.NET工作流管理系统
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .NET Remoting学习笔记(三)信道
  • .NET 回调、接口回调、 委托
  • .NET 依赖注入和配置系统
  • .NET/C# 使窗口永不激活(No Activate 永不获得焦点)
  • .NET学习教程二——.net基础定义+VS常用设置