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个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ... 
随机推荐
- python-ldap实现登录案例
			ldap_config = { 'ldap_path': 'ldap://xx.xx.xx.xx:389', 'base_dn': 'ou=users,dc=ledo,dc=com', 'ldap_u ... 
- Django messages框架
			一.简介 在网页应用中,你经常需要在处理完表单或其它类型的用户输入后,显示一个通知消息(也叫做“flash message”)给用户 对于这个功能,Django 提供基于Cookie 和会话的消息,无 ... 
- PDF.NET框架学习篇之SQL-MAP使用存储过程
			最近一直在学习“深蓝医生”的PDF.NET框架,对Sql-Map使用存储过程有了点小小的体会.基础知识请到http://www.cnblogs.com/bluedoctor/archive/2010/ ... 
- 20款时尚的 WordPress 简洁主题【免费下载】
			在这篇文章中,我们收集了20款时尚的 WordPress 简洁模板.WordPress 是最流行的博客系统,插件众多,易于扩充功能.安装和使用都非常方便,而且有许多第三方开发的免费模板,安装方式简单易 ... 
- 【HTML点滴】WWW简介
			www 什么是WWW www(world wide web),又称为万维网,或通常称为web,是一个基于超文本方式的信息检索服务工具. WWW的工作模式 C/S结构(client/server结构), ... 
- JS 事件代理
			事件处理器:onclick.onmouseover.... 在传统的事件处理中,你需要为每一个元素添加或者是删除事件处理器.然而,事件处理器将有可能导致内存泄露或者是性能下降——你用得越多这种风险就越 ... 
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
			One of the most important considerations when writing a select statement against a large table is th ... 
- charset的获取方法
			1.解析http请求的返回值: 2.通过解析html的meta标签里面的数据: 3.通过cpdetector(java环境下)来自动验证: ---------------------------- ... 
- Android Builder模式在开发中的应用
			最近在学习图片加载框架Glide的时候,被他精简的写法震惊了.一句话,就可以搞定. Glide.with(mContext) .load(url) .centerCrop() .placeholder ... 
- Android 采用HttpClient提交数据到服务器
			在前几篇文章中<Android 采用get方式提交数据到服务器><Android 采用post方式提交数据到服务器>介绍了android的两种提交数据到服务器的方法 本文继续介 ... 
