使用CocoaPods或者手动集成将CYLTabBarController这个第三方框架导入项目后,截图如下:

在AppDelegate.m类中实现的代码如下:

//  AppDelegate.m
// CYLTabBarController
//
// Created by mac on 16/1/28.
// Copyright © 2016年 mac. All rights reserved.
// #import "AppDelegate.h" #import <CYLTabBarController.h>
#import <CYLTabBar.h> #import "HomeViewController.h"
#import "MessageViewController.h"
#import "ComposeViewController.h"
#import "DiscoverViewController.h"
#import "MineViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //创建CYLTabBarController的对象
CYLTabBarController *CYLtabVC = [[CYLTabBarController alloc]init]; //设置CYLTabBarController对象的标签栏属性按钮
CYLtabVC.tabBarItemsAttributes = [self createTabBarItemsAttributes]; //设置CYLTabBarController对象的标签栏子控制器数组
CYLtabVC.viewControllers = [self createTabBarViewControllers]; //设置tabbar按钮的文字颜色
[self customizeInterface]; //设置添加按钮的事件,模态出发布控制器
if (CYLExternPushlishButton) { [CYLExternPushlishButton addTarget:self action:@selector(composeButtonClcked:) forControlEvents:UIControlEventTouchUpInside];
} //设置CYLTabBarController的对象的根控制器
[self.window setRootViewController:CYLtabVC]; return YES;
} #pragma mark - 模态出发布控制器
-(void)composeButtonClcked:(id)sender{ ComposeViewController *composeVC = [[ComposeViewController alloc]init];
[self.window.rootViewController presentViewController:composeVC animated:YES completion:nil];
} #pragma mark - 创建标签栏子控制器数组
-(NSArray *)createTabBarViewControllers{ //主页
HomeViewController *homeVC = [[HomeViewController alloc] init];
UINavigationController *homeNaV = [[UINavigationController alloc]initWithRootViewController:homeVC]; //消息
MessageViewController *messageVC = [[MessageViewController alloc] init];
UINavigationController *messageNaV = [[UINavigationController alloc]initWithRootViewController:messageVC]; //发现
DiscoverViewController *foundVC = [[DiscoverViewController alloc]init];
UINavigationController *foundNaV = [[UINavigationController alloc]initWithRootViewController:foundVC]; //我的
MineViewController *mineVC = [[MineViewController alloc]init];
UINavigationController *mineNaV = [[UINavigationController alloc]initWithRootViewController:mineVC]; return @[homeNaV,messageNaV,foundNaV,mineNaV];
} #pragma mark - 创建标签栏按钮item数组
-(NSArray *)createTabBarItemsAttributes{ NSDictionary *dict1 = @{
CYLTabBarItemTitle : @"首页",
CYLTabBarItemImage : @"tabbar_home",
CYLTabBarItemSelectedImage : @"tabbar_home_selected",
};
NSDictionary *dict2 = @{
CYLTabBarItemTitle : @"消息",
CYLTabBarItemImage : @"tabbar_message_center",
CYLTabBarItemSelectedImage : @"tabbar_message_center_selected",
};
NSDictionary *dict3 = @{
CYLTabBarItemTitle : @"发现",
CYLTabBarItemImage : @"tabbar_discover",
CYLTabBarItemSelectedImage : @"tabbar_discover_selected",
};
NSDictionary *dict4 = @{
CYLTabBarItemTitle : @"我的",
CYLTabBarItemImage : @"tabbar_profile",
CYLTabBarItemSelectedImage : @"tabbar_profile_selected",
};
return @[ dict1, dict2, dict3, dict4];
} #pragma mark - 设置tabbar按钮的文字颜色
- (void)customizeInterface { // 普通状态下的文字属性
NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor]; // 选中状态下的文字属性
NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
selectedAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor]; // 设置文字属性
UITabBarItem *tabBar = [UITabBarItem appearance];
[tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
[tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected]; // 设置背景图片
UITabBar *tabBarAppearance = [UITabBar appearance];
[tabBarAppearance setBackgroundImage:[UIImage imageNamed:@"tabbar_background"]];
}
@end

在需要添加的按钮类ComposeButton类中,实现的代码如下:

ComposeButton.h文件:

//  ComposeButton.h
// CYLTabBarController
//
// Created by mac on 16/1/28.
// Copyright © 2016年 mac. All rights reserved.
// #import <CYLPlusButton.h> @interface ComposeButton : CYLPlusButton<CYLPlusButtonSubclassing> @end

ComposeButton.h文件:

//  ComposeButton.m
// CYLTabBarController
//
// Created by mac on 16/1/28.
// Copyright © 2016年 mac. All rights reserved.
// #import "ComposeButton.h" @implementation ComposeButton +(void)load{
[super registerSubclass];
} +(instancetype)plusButton{ ComposeButton *composeButton = [[ComposeButton alloc]initWithFrame:CGRectMake(, , , )]; //设置背景
[composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
[composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted]; //设置按钮
[composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
[composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected]; return composeButton;
} //返回插入位置,因为是奇数,所以不用指定安放的位置,它会自动调整位置
//+ (NSUInteger)indexOfPlusButtonInTabBar{
//
// return 2;
//} @end

在发布控制器中实现的是代码:ComposeViewController.m

//  ComposeViewController.m
// CYLTabBarController
//
// Created by mac on 16/1/28.
// Copyright © 2016年 mac. All rights reserved.
// #import "ComposeViewController.h" @interface ComposeViewController ()
@property (strong,nonatomic)UIToolbar *topToolBar;
@end #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height @implementation ComposeViewController /**
* 设置工具栏
*/
-(void)viewWillAppear:(BOOL)animated{ [[UIToolbar appearance]setTintColor:[UIColor brownColor]]; self.topToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(, , SCREEN_WIDTH, )]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftItemBack:)]; UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *midItem = [[UIBarButtonItem alloc]initWithTitle:@"发布新微薄" style:UIBarButtonItemStylePlain target:nil action:nil];
[midItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
[midItem setEnabled:NO]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(rightItemSend:)]; self.topToolBar.items = @[leftItem,flexItem,midItem,flexItem,rightItem]; [self.view addSubview:self.topToolBar];
} - (void)viewDidLoad {
[super viewDidLoad]; self.title = @"发布";
self.view.backgroundColor = [UIColor lightGrayColor];
} #pragma mark - 返回按钮事件,关闭模态的发布控制器
-(void)leftItemBack:(UIBarButtonItem *)sender{ [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
} #pragma mark - 发布按钮事件,发布新的微博
-(void)rightItemSend:(UIBarButtonItem *)sender{ NSLog(@"%s",__func__);
} @end

演示截图如下:                                         点击发布按钮时:

 

iOS:CYLTabBarController的具体使用实例:实现新浪微博的主流框架的更多相关文章

  1. iOS之UI--涂鸦画板实例

     iOS之UI--涂鸦画板实例  首先是搭建框架 其他的略过,直接展示效果: 然后接下来上传搭建好两个控制器框架的源码百度云下载链接: http://pan.baidu.com/s/1skjpDox  ...

  2. 实例演示使用RDIFramework.NET 框架的工作流组件进行业务流程的定义—请假申请流程-Web

    实例演示使用RDIFramework.NET 框架的工作流组件 进行业务流程的定义—请假申请流程-Web 参考文章: RDIFramework.NET — 基于.NET的快速信息化系统开发框架 — 系 ...

  3. Windows 8实例教程系列 - 理解应用框架

    原文:Windows 8实例教程系列 - 理解应用框架 Windows 操作系统之所以风靡世界,是因为其“易学易用”,从用户的角度出发,让数以万计的非IT人员使用计算机实现娱乐,工作等目的.Windo ...

  4. iOS开发- UICollectionView详解+实例

    本章通过先总体介绍UICollectionView及其常用方法,再结合一个实例,了解如何使用UICollectionView. UICollectionView 和 UICollectionViewC ...

  5. Delphi xe7 FireMonkey / Mobile (Android, iOS)生成 QR Code完整实例

    这个实例在windows.OS X.IOS和Android等平台运行正常.本文参考这个网站提供的方法:http://zarko-gajic.iz.hr/firemonkey-mobile-androi ...

  6. [转] iOS开发- UICollectionView详解+实例

    本章通过先总体介绍UICollectionView及其常用方法,再结合一个实例,了解如何使用UICollectionView. UICollectionView 和 UICollectionViewC ...

  7. iOS 新浪微博-1.1框架升级

    在iOS 新浪微博-1.0框架搭建 中,使用的是xcode5.1.1开发.现在把重整了一下框架 改为xcode7.0开发 使用cocoaPad管理第三方库 程序将托管到github上 在改为xcode ...

  8. iOS中的成员变量,实例变量,属性变量

    在ios第一版中: 我们为输出口同时声明了属性和底层实例变量,那时,属性是oc语言的一个新的机制,并且要求你必须声明与之对应的实例变量,例如: 注意:(这个是以前的用法) @interface MyV ...

  9. iOS仿京东分类菜单实例实现

    在APP开发过程中此功能还是比较常见的模块,左边为菜单展示,右边为菜单下数据的展示,选择不同的菜单右边的数据源进行更新,此实例主要运用到UITableView,UICollectionView,OC谓 ...

随机推荐

  1. mac pro 安装mysql并且配置my.cnf(添加默认字符集utf8,数据存放路径,修改已经建好的表的默认字符集等)、mac mysql my.cnf路径

    如果你是还没有下载安装文件,请到官网下载http://dev.mysql.com/downloads/mysql/ 下载好mysql的mac版本的安装文件后解压后将文件放到目录 /usr/local/ ...

  2. CodeForces 450B

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Mybatis学习—XML配置文件

    总结自 Mybatis官方中文文档 XML 映射配置文件 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置(settings)和属性(properties)信息.文档的顶层结构如 ...

  4. 操作cephfs的基本命令

    [前提是已有一个基本可用的ceph集群] 一,在指定节点上部署mds: ceph-deploy mds create ceph-node1 二,新建两个存储池,用于保存cephfs的数据和元数据. c ...

  5. 【转】kubernetes 中 deployment 支持哪些键值

    这个比较全,可以参考 ================= https://www.addops.cn/post/kubernetes-deployment-fileds.html ========== ...

  6. 关于在C#中对类中的隐藏基类方法和重写方法的理解

    最近在学习C#,在C#中的类看到重写和隐藏基类的方法这些概念.才开始感觉自己不是很理解这些概念.也区分不开这些概念.通过自己的查找资料和练习后.慢慢的理解了类中的隐藏和重写这个概念.在C#中只有在基类 ...

  7. Java字符串易错方法总结

    Java字符串易错方法总结 public String[] split(String regex) 和 public String[] split(String regex,int limit) li ...

  8. 2017 Hackatari Codeathon C. Arcade(DP)(滚动数组)

    C. Arcade time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  9. 从Linux下载文件到Windows没有换行问题

    这是一个小问题,一般用txt打开文件才会遇到,word打开也是正常(估计其他编程软件打开也正常). 顺便提一下pscp从Linux上下载文件到Windows. C:\Users\xuefei>p ...

  10. NetCore项目的部署

    NetCore项目和以前的AspNet项目在部署上有很大的不同,因为NetCore是跨平台的 NetCore支持Kestrel和IIS两种方式,看代码的11行和14行 using System.IO; ...