TabbarController进行模块分类和管理
iOS-CYLTabBarController【好用的TabbarController】
用TabbarController进行模块分类和管理,这里推荐一个CYLTabBarController,只需两个数组就可以使用和管理;
1.导入CYLTabBarController
使用cocoapods导入即可 pod 'CYLTabBarController', '~> 1.14.1',终端 pod install 即可
2.配置
新建一个基于 NSObject 类 MainTabBarControllerConfig,用于配置CYLTabBarController及管理;头文件引入
#import <CYLTabBarController.h>
.h
@interface MainTabBarControllerConfig : NSObject
///CYLTabBarController
@property (nonatomic,strong) CYLTabBarController *mainTabBarController;
@end
.m

@implementation MainTabBarControllerConfig
- (CYLTabBarController *)mainTabBarController{
if (!_mainTabBarController) {
UIEdgeInsets imageInsets = UIEdgeInsetsZero;
UIOffset titlePositionAdjustment = UIOffsetZero;
_mainTabBarController = [CYLTabBarController tabBarControllerWithViewControllers:[self arrayViewControllerItem] tabBarItemsAttributes:[self arrayAttributesItem] imageInsets:imageInsets titlePositionAdjustment:titlePositionAdjustment];
[self customizeTabBarAppearance:_mainTabBarController];
}
return _mainTabBarController;
}
- (NSArray *)arrayViewControllerItem{
BookcaseNavViewController *bookcaseNavi = [wkj_getSboardBookcase instantiateViewControllerWithIdentifier:@"BookcaseNavViewController"];
AskKaoLaNavViewController *askKlNavi = [wkj_getSboardAskKaoLa instantiateViewControllerWithIdentifier:@"AskKaoLaNavViewController"];
DiscoverNavViewController *discoverNavi = [wkj_getSboardDiscover instantiateViewControllerWithIdentifier:@"DiscoverNavViewController"];
UserNavViewController *userNavi = [wkj_getSboardUser instantiateViewControllerWithIdentifier:@"UserNavViewController"];
///返回需要加载的模块
return @[bookcaseNavi,discoverNavi,askKlNavi,userNavi];
}
- (NSArray *)arrayAttributesItem{
NSDictionary *bookcaseItemsAttributes =@{CYLTabBarItemTitle : @"nav1",
CYLTabBarItemImage : @"bar_tk_01",
/* NSString and UIImage are supported*/
CYLTabBarItemSelectedImage : @"bar_tk_02",};
NSDictionary *discoverItemsAttributes = @{CYLTabBarItemTitle : @"nav2",
CYLTabBarItemImage : @"bar_kc_01",
CYLTabBarItemSelectedImage : @"bar_kc_02",};
NSDictionary *askklItemsAttributes = @{CYLTabBarItemTitle : @"nav3",
CYLTabBarItemImage : @"bar_dzs_01",
CYLTabBarItemSelectedImage : @"bar_dzs_02",};
NSDictionary *userItemsAttributes = @{CYLTabBarItemTitle : @"nav4",
CYLTabBarItemImage : @"bar_wd_01",
CYLTabBarItemSelectedImage : @"bar_wd_02"};
NSArray *tabBarItemsAttributes = @[bookcaseItemsAttributes,
discoverItemsAttributes,
askklItemsAttributes,
userItemsAttributes];
return tabBarItemsAttributes;
}
/**
* 更多TabBar自定义设置:比如:tabBarItem 的选中和不选中文字和背景图片属性、tabbar 背景图片属性等等
*/
- (void)customizeTabBarAppearance:(CYLTabBarController *)tabBarController {
// Customize UITabBar height
// 自定义 TabBar 高度
// tabBarController.tabBarHeight = CYLTabBarControllerHeight;
// set the text color for unselected state
// 普通状态下的文字属性
NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
// set the text color for selected state
// 选中状态下的文字属性
NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
selectedAttrs[NSForegroundColorAttributeName] = Wonderful_BlueColor6;
// set the text Attributes
// 设置文字属性
UITabBarItem *tabBar = [UITabBarItem appearance];
[tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
[tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
// Set the dark color to selected tab (the dimmed background)
// TabBarItem选中后的背景颜色
// [self customizeTabBarSelectionIndicatorImage];
// update TabBar when TabBarItem width did update
// If your app need support UIDeviceOrientationLandscapeLeft or UIDeviceOrientationLandscapeRight,
// remove the comment '//'
// 如果你的App需要支持横竖屏,请使用该方法移除注释 '//'
// [self updateTabBarCustomizationWhenTabBarItemWidthDidUpdate];
// set the bar shadow image
// This shadow image attribute is ignored if the tab bar does not also have a custom background image.So at least set somthing.
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tapbar_top_line"]];
// set the bar background image
// 设置背景图片
// UITabBar *tabBarAppearance = [UITabBar appearance];
// [tabBarAppearance setBackgroundImage:[UIImage imageNamed:@"tab_bar"]];
// remove the bar system shadow image
// 去除 TabBar 自带的顶部阴影
// [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
}

3.使用
在AppDelegate.m didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// /加载中间自定义按钮
// [TabbarPlusButton registerPlusButton];
MainTabBarControllerConfig *tabbarConfig = [[MainTabBarControllerConfig alloc]init];
CYLTabBarController *mainTabbarController = tabbarConfig.mainTabBarController;
[self.window setRootViewController:mainTabbarController];
return YES;
}


4.自定义按钮
加入中间按钮之前,确保上面的功能已经实现;新建一个基于 CYLPlusButton 的类 TabbarPlusButton,实现代理 CYLPlusButtonSubclassing
.h
@interface TabbarPlusButton : CYLPlusButton<CYLPlusButtonSubclassing> @end
.m

@implementation TabbarPlusButton
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.adjustsImageWhenHighlighted = NO;
}
return self;
}
//上下结构的 button
- (void)layoutSubviews {
[super layoutSubviews];
// 控件大小,间距大小
// 注意:一定要根据项目中的图片去调整下面的0.7和0.9,Demo之所以这么设置,因为demo中的 plusButton 的 icon 不是正方形。
CGFloat const imageViewEdgeWidth = self.bounds.size.width * 0.7;
CGFloat const imageViewEdgeHeight = imageViewEdgeWidth * 0.9;
CGFloat const centerOfView = self.bounds.size.width * 0.5;
CGFloat const labelLineHeight = self.titleLabel.font.lineHeight;
CGFloat const verticalMargin = (self.bounds.size.height - labelLineHeight - imageViewEdgeHeight) * 0.5;
// imageView 和 titleLabel 中心的 Y 值
CGFloat const centerOfImageView = verticalMargin + imageViewEdgeHeight * 0.5;
CGFloat const centerOfTitleLabel = imageViewEdgeHeight + verticalMargin * 2 + labelLineHeight * 0.5 + 5;
//imageView position 位置
self.imageView.bounds = CGRectMake(0, 0, imageViewEdgeWidth, imageViewEdgeHeight);
self.imageView.center = CGPointMake(centerOfView, centerOfImageView);
//title position 位置
self.titleLabel.bounds = CGRectMake(0, 0, self.bounds.size.width, labelLineHeight);
self.titleLabel.center = CGPointMake(centerOfView, centerOfTitleLabel);
}
#pragma mark -
#pragma mark - CYLPlusButtonSubclassing Methods
/*
*
Create a custom UIButton with title and add it to the center of our tab bar
*
*/
+ (id)plusButton {
TabbarPlusButton *button = [[TabbarPlusButton alloc] init];
///中间按钮图片
UIImage *buttonImage = [UIImage imageNamed:@"post_normal"];
[button setImage:buttonImage forState:UIControlStateNormal];
[button setTitle:@"发布" forState:UIControlStateNormal];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[button setTitle:@"发布" forState:UIControlStateSelected];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
button.titleLabel.font = [UIFont systemFontOfSize:9.5];
[button sizeToFit]; // or set frame in this way `button.frame = CGRectMake(0.0, 0.0, 250, 100);`
// button.frame = CGRectMake(0.0, 0.0, 250, 100);
// button.backgroundColor = [UIColor redColor];
// if you use `+plusChildViewController` , do not addTarget to plusButton.
[button addTarget:button action:@selector(clickPublish) forControlEvents:UIControlEventTouchUpInside];
return button;
}
/*
*
Create a custom UIButton without title and add it to the center of our tab bar
*
*/
//+ (id)plusButton
//{
//
// UIImage *buttonImage = [UIImage imageNamed:@"hood.png"];
// UIImage *highlightImage = [UIImage imageNamed:@"hood-selected.png"];
//
// CYLPlusButtonSubclass* button = [CYLPlusButtonSubclass buttonWithType:UIButtonTypeCustom];
//
// button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
// button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
// [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
// [button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
// [button addTarget:button action:@selector(clickPublish) forControlEvents:UIControlEventTouchUpInside];
//
// return button;
//}
#pragma mark -
#pragma mark - Event Response
- (void)clickPublish {
CYLTabBarController *tabBarController = [self cyl_tabBarController];
UIViewController *viewController = tabBarController.selectedViewController;
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"拍照", @"从相册选取", @"淘宝一键转卖", nil];
[actionSheet showInView:viewController.view];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"buttonIndex = %@", @(buttonIndex));
}
#pragma mark - CYLPlusButtonSubclassing
//+ (UIViewController *)plusChildViewController {
// UIViewController *plusChildViewController = [[UIViewController alloc] init];
// plusChildViewController.view.backgroundColor = [UIColor redColor];
// plusChildViewController.navigationItem.title = @"PlusChildViewController";
// UIViewController *plusChildNavigationController = [[UINavigationController alloc]
// initWithRootViewController:plusChildViewController];
// return plusChildNavigationController;
//}
//
//+ (NSUInteger)indexOfPlusButtonInTabBar {
// return 4;
//}
//
//+ (BOOL)shouldSelectPlusChildViewController {
// BOOL isSelected = CYLExternPlusButton.selected;
// if (isSelected) {
// NSLog(@"
TabbarController进行模块分类和管理的更多相关文章
- nginx中的模块分类及常见核心模块有哪些
1.模块分类 核心模块:是 Nginx 服务器正常运行必不可少的模块,提供错误日志记录 .配置文件解析 .事件驱动机制 .进程管理等核心功能 标准HTTP模块:提供 HTTP 协议解析相关的功能,比如 ...
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
本次python爬虫百步百科,里面详细分析了爬虫的步骤,对每一步代码都有详细的注释说明,可通过本案例掌握python爬虫的特点: 1.爬虫调度入口(crawler_main.py) # coding: ...
- ansible笔记(9):常用模块之包管理模块
ansible笔记():常用模块之包管理模块 yum_repository模块 yum_repository模块可以帮助我们管理远程主机上的yum仓库. 此处我们介绍一些yum_repository模 ...
- SAP 财务模块 FI-TV 差旅管理
SAP 财务模块 FI-TV 差旅管理 Travel Management差旅管理事务码 描述PRT3 Trip Costs: Maintain Postings ...
- sqlalchemy tree 树形分类 无限极分类的管理。预排序树,左右值树。sqlalchemy-mptt
简介: 无限极分类是一种比较常见的数据格式,生成组织结构,生成商品分类信息,权限管理当中的细节权限设置,都离不开无限极分类的管理. 常见的有链表式,即有一个Pid指向上级的ID,以此来设置结构.写的时 ...
- 论坛模块_版块管理_增删改查&实现上下移动
论坛模块_版块管理1_增删改查 设计实体Forum.java public class Forum { private Long id; private String name; private St ...
- 系统管理模块_用户管理1_实现用户有关的功能_测试功能、解决事务的问题、对密码进行MD5摘要
系统管理模块__用户管理1__实现用户有关的功能 了解用户管理要做什么(增删改查初始化密码) 设计实体 分析功能有几个对应几个请求 增删改查有6个请求,初始化密码一个 实现增删改查一组功能的步骤流程 ...
- 系统管理模块_部门管理_改进_抽取添加与修改JSP页面中的公共代码_在显示层抽取BaseAction_合并Service层与Dao层
系统管理模块_部门管理_改进1:抽取添加与修改JSP页面中的公共代码 commons.jspf <%@ page language="java" import="j ...
- 系统管理模块_岗位管理_实现CRUD功能的具体步骤并设计Role实体
系统管理模块_岗位管理_实现CRUD功能的具体步骤并设计Role实体 1,设计实体/表 设计实体 --> JavaBean --> hbm.xml --> 建表 设计Role实体 p ...
随机推荐
- 6、图标:icon
1.图标 /* ---html----*/ <ion-content text-center class="icons-basic-page"> <ion-row ...
- 嵌入式Tomcat Web服务器的使用
在运行web工程时,常常要频繁启动tomcat,使用嵌入式tomcat可以减少部分重复操作. 1.下载tomcat5.0.28embed.zip 解压文件夹复制到工程下. http://archive ...
- C# ADO.NET
ADO.NET 作业总结难点 数据库语句掌握太差 //查询 select * from Users //查询表中所有数据 select * from Users where UserName = 'l ...
- Java笔记之Scanner先读取一个数字,在读取一行字符串方法分析
问题:大家在学习Java读取数据的时候一般都是使用Scanner方法读取数据,但是其中有一个小问题大家可能不知道, 就是我们在使用scanner的时候如果你先读取一个数字,在读取一行带有空格的字符串, ...
- csharp: DataTable结构相同的比较
)
) * pageSize;
; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (Dat ...
- html5 填表 表单 input output 与表单验证
1.<output> Js计算结果 <form oninput="res.value = num1.valueAsNumber*num2.valueAsNumber ...
- mongodb 32为安装
启动命令:mongod --dbpath D:\MongoDB\data --logpath c:\MongoDB\log\mongod.log --journal 安装引擎: mongod --db ...
- 针对 IE的 的优化
针对 IE 的优化 有些时候,你需要对 IE 浏览器的 bug 定义一些特别的规则,这里有太多的 CSS 技巧(hacks),我只使用其中的两种方法,不 管微软在即将发布的 IE7 beta 版里是否 ...
- JS监测鼠标指针位置
需求1:鼠标移入正方形的时候,蓝色小圆点跟随鼠标滚动(不许蓝色小圆点超出正方形区域),正方形里实时显示当前鼠标相对于body的坐标. <!DOCTYPE html> <html la ...
- 详解Struts1.x的运行机制及命名规则
Struts1.x 调用一个action的大致流程: 1)首先前端发送 *.do的一个action请求(通过点击表单提交按钮,js 事件等): 2)web.xml 文件通过 *.do 找到 Actio ...