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个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
随机推荐
- MySQL日期处理(笔记)
对于刚学习MySQL的人日期的处理是个大坑. 这里整理了如何处理常见的日期问题. (这只是我在学习过程中关于日期处理方面知识的总结,会有一些错误和片面的地方.) Date 函数 函数 描述 NOW() ...
- Atitit.提升语言可读性原理与实践
Atitit.提升语言可读性原理与实践 表1-1 语言评价标准和影响它们的语言特性1 1.3.1.2 正交性2 1.3.2.2 对抽象的支持3 1.3.2.3 表达性3 .6 语言设计中的权 ...
- MontageJS:构建现代 Web App 的 HTML5 框架
MontageJS 可以帮助您构建高可扩展性和可维护性的 HTML5 应用.有了 MontageJS,开发人员可以创建可重用的用户界面组件和模块,组件和控制器之间的绑定属性,并且同步 DOM 查询和更 ...
- C#关于word文档的书签替换操作
public void Get_Word(string gjbh) { try { DataSet ds = OperaterBase.GetDsBySql("select diffTabl ...
- 一个巧妙的实现悬浮的tableViewHeader的方法
之前因为工作需要要实现一个类似的 悬浮+视差的headerView的效果, 研究了好久没研究出来怎么做,最后用UICollectionView + CSStickyHeaderFlowLayout的方 ...
- Android提交数据到JavaWeb服务器实现登录
之前学习Android提交数据到php服务器没有成功,在看了两三个星期的视频之后,现在终于实现了与服务器的交互.虽然完成的不是PHP端的,但是在这个过程还是学到了不少东西的.现在我先来展示一下我的成果 ...
- ‘Cordova/CDVPlugin.h’ file not found
phonegap项目,平时真机调试没什么问题.然后想打包成ipa了,去Product --> Archive 一下,然后就报错了,说:‘Cordova/CDVPlugin.h’ file not ...
- Android 插件化
1.介绍 涛哥写的文章 <Android 插件化的 过去 现在 未来> http://kymjs.com/code/2016/05/04/01#rd
- iOS中View生命周期与布局
生命周期 说到view的生命周期一般都是指视图控制器的view生命周期. view的创建:loadView 视图控制器(UIViewController)及其子类,无论是手写代码还是storyboar ...
- Web应用程序系统的多用户权限控制设计及实现-权限模块【10】
前五章均是从整体上讲述了Web应用程序的多用户权限控制实现流程,本章讲述Web权限管理系统的权限配置模块.页面模块涉及到的数据表为权限表.权限配置模块是按照用户组和页面,栏目结合组成的.通过配置一个用 ...