iOS 实现Tabbarcontroller中间自定义样式 最简单的方法
先上图:

如果我们要实现中间按钮自定义样式,方法应该蛮多,这里介绍一种最简单的。
1、创建类继承:UITabBarController,如下代码都是写在该类的 .m文件里
2、定义最中间的自定义样式,写在viewDidLoad里
UIButton *btn = [[UIButton alloc] init];
btn.layer.cornerRadius = 30;
btn.layer.masksToBounds = YES;
btn.backgroundColor = [UIColor redColor];
btn.frame = CGRectMake(0, 0, 60, 60);
CGPoint center = self.tabBar.center;
center.y=center.y-15;
btn.center = center;
[self.view addSubview:btn];
[btn addTarget:self action:@selector(hhhCLick) forControlEvents:UIControlEventTouchUpInside];
这里解释一下:
我们获取当前tabbar的center点,然后自定义一个按钮,给予自己想要的样式,然后add上去。
这里要注意一点,这里用的自定义按钮,没有用系统tabbarItem,所以最后setViewController的时候要留出位置。
完整代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
HomeViewController *home = [[HomeViewController alloc] init];
UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:home];
home.title = @"相册";
home.navigationItem.title = @"相册";
home.tabBarItem.image = [[UIImage imageNamed:@"home"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
home.tabBarItem.selectedImage = [[UIImage imageNamed:@"home_selected"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
VideoViewController *pic = [[VideoViewController alloc] init];
UINavigationController *picNav = [[UINavigationController alloc] initWithRootViewController:pic];
pic.title = @"视频";
pic.navigationItem.title = @"视频";
pic.tabBarItem.image = [[UIImage imageNamed:@"picture"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
pic.tabBarItem.selectedImage = [[UIImage imageNamed:@"picture_selected"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
SeetingViewController *setting = [[SeetingViewController alloc] init];
UINavigationController *setNav = [[UINavigationController alloc] initWithRootViewController:setting];
setting.tabBarItem.title = @"设置";
setting.navigationItem.title = @"设置";
setting.tabBarItem.image = [[UIImage imageNamed:@"setting"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
setting.tabBarItem.selectedImage = [[UIImage imageNamed:@"setting_selected"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
SeetingViewController *setting222 = [[SeetingViewController alloc] init];
UINavigationController *setNav222 = [[UINavigationController alloc] initWithRootViewController:setting222];
setting222.tabBarItem.title = @"设置2";
setting222.navigationItem.title = @"设置2";
setting222.tabBarItem.image = [[UIImage imageNamed:@"setting"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
setting222.tabBarItem.selectedImage = [[UIImage imageNamed:@"setting_selected"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
NSMutableArray *arry = [[NSMutableArray alloc] init];
[arry addObject:homeNav];
[arry addObject:picNav];
[arry addObject:[UIViewController new]];
[arry addObject:setNav222];
[arry addObject:setNav];
[self setViewControllers:arry animated:YES];
//-----------这里是自定义样式按钮-----------
UIButton *btn = [[UIButton alloc] init];
btn.layer.cornerRadius = 30;
btn.layer.masksToBounds = YES;
btn.backgroundColor = [UIColor redColor];
btn.frame = CGRectMake(0, 0, 60, 60);
CGPoint center = self.tabBar.center;
center.y=center.y-15;
btn.center = center;
[self.view addSubview:btn];
[btn addTarget:self action:@selector(hhhCLick) forControlEvents:UIControlEventTouchUpInside];
}
点击按钮事件,自己可以Modal到新控制器。
-(void)hhhCLick{
SeetingViewController *setting111 = [[SeetingViewController alloc] init];
UINavigationController *setNav111 = [[UINavigationController alloc] initWithRootViewController:setting111];
setting111.tabBarItem.title = @"";
setting111.navigationItem.title = @"设置1";
[self presentViewController:setNav111 animated:YES completion:nil];
}
iOS 实现Tabbarcontroller中间自定义样式 最简单的方法的更多相关文章
- iOS 中使用 XIB 自定义cell 的两种方法 以及 编译出现常见 的错误 ++++(xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- vue点击时动态改变样式 ------- 最简单的方法
vue点击时动态改变样式 template中 <li :class="{ active:index==isActive }" @click="changeValue ...
- iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- 移动端ios下H5的:active样式失效的解决方法
在body上绑定一个touchstart事件,空函数就行: document.body.addEventListener('touchstart', function(){}, false) 或者在b ...
- Yii2 ActiveForm表单自定义样式
实例: <?php $form = ActiveForm::begin([ 'fieldConfig' => [ 'template' => '<div class=" ...
- Dialog详解(包括进度条、PopupWindow、自定义view、自定义样式的对话框)
Dialog详解(包括进度条.PopupWindow.自定义view.自定义样式的对话框) Android中提供了多种对话框,在实际应用中我们可能会需要修改这些已有的对话框.本实例就是从实际出发, ...
- 超详细的Xcode代码格式化教程,可自定义样式。
超详细的Xcode代码格式化教程,可自定义样式. 为什么要格式化代码 当团队内有多人开发的时候,每个人写的代码格式都有自己的喜好,也可能会忙着写代码而忽略了格式的问题.在之前,我们可能会写完代码后,再 ...
- [置顶]
bootstrap自定义样式-bootstrap侧边导航栏的实现
前言 bootstrap自带的响应式导航栏是向下滑动的,有时满足不了个性化的需求,需要做一个类似于android drawerLayout 侧滑的菜单,这就是我要实现的bootstrap自定义侧滑菜单 ...
- Expo大作战(十二)--expo中的自定义样式Custom font,以及expo中的路由Route&Navigation
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
随机推荐
- gcd和ex_gcd
gcd就是欧几里得算法,可以快速的求出俩个数的最大公因数,进而也可以求其最大公倍数(俩数之积除以最大公因数),比较简单直接看代码就好了,一般用递归版,简短精简,敲得快,但如果数剧奇葩,怕溢出,那就用递 ...
- ErrorExecution failed for task 'apptransformClassesWithDexForDebug'
[原因]: 在工程中既有本地的lib.jar文件,又有compile链接.
- sublime text 之添加插件 并使用
通过package controll install 安装各种插件: 1:AdvancedNewFile,安装完毕后 快捷键:ctr+alt+n:输入框中输入你要创建的文件夹和文件,就创建好了. ...
- JavaScript事件对象
一. 事件对象 事件处理三部分组成:对象.事件处理函数=函数.例如:单击文档任意处. 1.鼠标按钮 非 IE(W3C)中的 button 属性 0 表示主鼠标按钮(常规一般是鼠标左键) 1 表示中间的 ...
- JavaScript数组与对象的关系
JavaScript的数组,相比其他语言,是比较特殊的.数组是Object类型,只不过,有几个比较特殊的地方: 有索引下标 有默认的length属性 是有序的(注意,对象是无序的) 可以使用一些特殊的 ...
- 原生JS:Math对象详解
Math对象 本文参考MDN做的详细整理,方便大家参考MDN Math 也是一个内置对象, 为数学常量和数学函数提供了属性和方法,而不是一个函数对象. 与其它全局对象不同的是, Math 不是一个构造 ...
- ABAP--关于ABAP流程处理的一些命令的说明(stop,exit,return,check,reject)
Stop 命令 使用该命令的程序位置 INITIALIZATION, AT SELECTION-SCREEN, START-OF-SELECTION和GET 事件中 处理说明 1. 当在INITIAL ...
- SharePoint2010升级到SharePoint2013操作手册
SharePoint2010升级到SharePoint2013操作手册 目 录 第一章 前言 3 第二章 升级前准备 3 第三章 升级流程图 5 第四章 升级过程 5 4.1 ...
- 如何:对 SharePoint 列表项隐藏 ECB 中的菜单项
可以通过使用功能框架向编辑控制块 (ECB) 菜单添加新的自定义操作.但是,您不能使用此方法进行相反的操作,即隐藏现有的 ECB 菜单项,因为它们是通过使用 ECMAScript(JavaScript ...
- Large-file-chunk-size 设置最大文件上传值
Large-file-chunk-size: Stsadm property (Office SharePoint Server) SharePoint 2007 0 out of 1 rated ...