先上图:

如果我们要实现中间按钮自定义样式,方法应该蛮多,这里介绍一种最简单的。

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中间自定义样式 最简单的方法的更多相关文章

  1. iOS 中使用 XIB 自定义cell 的两种方法 以及 编译出现常见 的错误 ++++(xcode6.0之后)

    一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...

  2. vue点击时动态改变样式 ------- 最简单的方法

    vue点击时动态改变样式 template中 <li :class="{ active:index==isActive }" @click="changeValue ...

  3. iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)

    一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...

  4. 移动端ios下H5的:active样式失效的解决方法

    在body上绑定一个touchstart事件,空函数就行: document.body.addEventListener('touchstart', function(){}, false) 或者在b ...

  5. Yii2 ActiveForm表单自定义样式

    实例: <?php $form = ActiveForm::begin([ 'fieldConfig' => [ 'template' => '<div class=" ...

  6. Dialog详解(包括进度条、PopupWindow、自定义view、自定义样式的对话框)

    Dialog详解(包括进度条.PopupWindow.自定义view.自定义样式的对话框)   Android中提供了多种对话框,在实际应用中我们可能会需要修改这些已有的对话框.本实例就是从实际出发, ...

  7. 超详细的Xcode代码格式化教程,可自定义样式。

    超详细的Xcode代码格式化教程,可自定义样式. 为什么要格式化代码 当团队内有多人开发的时候,每个人写的代码格式都有自己的喜好,也可能会忙着写代码而忽略了格式的问题.在之前,我们可能会写完代码后,再 ...

  8. [置顶] bootstrap自定义样式-bootstrap侧边导航栏的实现

    前言 bootstrap自带的响应式导航栏是向下滑动的,有时满足不了个性化的需求,需要做一个类似于android drawerLayout 侧滑的菜单,这就是我要实现的bootstrap自定义侧滑菜单 ...

  9. Expo大作战(十二)--expo中的自定义样式Custom font,以及expo中的路由Route&Navigation

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

随机推荐

  1. 2016 大连网赛---Weak Pair(dfs+树状数组)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...

  2. Java基础复习笔记系列 十三 反射机制

    主题:Java反射机制 学习资料参考网址: 1.http://www.icoolxue.com 1.Java反射机制. 各种框架中都使用到了Java的反射机制. 两个类:java.lang.Class ...

  3. orcl的小技巧和分页

    1Oracle中查看所有用户语句 select * from dba_users 1.修改用户的密码 alter user 用户名 identified by 密码; 2.如何查询stuInfo表中自 ...

  4. Test your application

    Creating automatic test suites for your application is a good way to make it robust. It allows you t ...

  5. 关于clientWidth scrollWidth offsetWidth的理解

    clientWidth:元素可见区域的宽度  clientWidth=padding+width-滚动条 scrollWidth:元素实际内容的宽度 scrollWidth=padding+width ...

  6. 15款精美的 WordPress 电子商务网站模板

    在这篇文章中,我们收集了15款精美的 WordPress 电子商务网站模板.WordPress 作为最流行的博客系统,插件众多,易于扩充功能.安装和使用都非常方便,而且有许多第三方开发的免费模板,安装 ...

  7. 运用Gulp压缩文件编译文件。包括css js html image

    安装node.js  npm  以及安装gulp等方法我就不在这里赘述了. 接下里我主要介绍的是Gulpfile文件里面的配置该如何书写. var gulp = require('gulp');//引 ...

  8. 学习zepto.js(原型方法)[2]

    接着昨天的来,继续说原型方法,昨天的传送阵(昨天出了点小意外,博文经过WP手机的UC浏览器进行编辑后标签就露出来了- -,现已修复); $.grep(): 作用与Array.filter类似(其实就是 ...

  9. rem在响应式布局中的应用

    rem/em/px/pt的基友关系 px 像素相对长度单位,相对于显示器屏幕分辨率而言 em 相对长度单位,根据其父元素来设置字体大小 pt point,是印刷行业常用单位,等于1/72英寸 rem ...

  10. NMAP实用手册

    nmap在网络和渗透中使用相当频繁,相关教程也层出不穷.在此,我只整理出最实用的,言简意赅,方便自己,方便他人. 一.nmap介绍 NMAP,也就是Network Mapper,最早是Linux下的网 ...