push页面时,可调用hidesBottomBarWhenPushed进行隐藏。

第一步,我们需要一些图片:

各个选项的图标和tabbar的背景图片,最后还要一个透明的1x1像素的图片。

第二步,新建一个工程,在工程内建一个继承于UITabBarController的类。

第三步,首先写一个方法,返回一个UINavigationController

  1. -(UINavigationController*) viewControllerWithTitle:(NSString*) title image:(UIImage*)image
  2. {
  3. UIViewController* viewController = [[UIViewController alloc] init];
  4. viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
  5. viewController.title = title;
  6. UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
  7. return nav;
  8. }

然后在viewDidLoad里面创建TabbarController的viewControllers

  1. self.viewControllers = [NSArray arrayWithObjects:
  2. [self viewControllerWithTitle:@"1" image:IMG(@"1")],
  3. [self viewControllerWithTitle:@"2" image:IMG(@"2")],
  4. [self viewControllerWithTitle:nil image:nil],
  5. [self viewControllerWithTitle:@"3" image:IMG(@"3")],
  6. [self viewControllerWithTitle:@"4" image:IMG(@"4")], nil nil];

看到没有,比较猥琐的就是第三个ViewController什么都没设置。

因为我们要在那个位置放一个自己的按钮,继续在viewDidLoad写:

  1. UIButton* button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 65, 65)];
  2. button.center = CGPointMake(160, 20);
  3. [button setBackgroundImage:IMG(@"add") forState:UIControlStateNormal];
  4. [button addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
  5. [self.tabBar addSubview:button];

然后设置背景图片:

  1. [self.tabBar setBackgroundImage:IMG(@"tabbarbg")];

运行之后是这样的:

会发现按钮上面有一条横线,然后再设置这个阴影运行后就没有人发现你猥琐的行径。

  1. [self.tabBar setShadowImage:IMG(@"transparent")];

最后效果图(iOS7和iOS6):

这样做的好处:

在ViewController里push页面的时候可调用hidesBottomBarWhenPushed的属性进行隐藏。

最新文章

  1. 【UI插件】简单的日历插件(下)—— 学习MVC思想
  2. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
  3. FFT的分析以及matlab实验
  4. android 应用笔记
  5. 一张图让你看懂各开源License[转]
  6. C# 运行时编辑 节点重命名
  7. Windows 小技巧: 變更輸入法順序
  8. 利用 SerialPort 控件实现 PC 串口通信
  9. 初识CLR
  10. hdu4707 Pet
  11. 浅析——SCTP协议(转)
  12. pptv web前端面试题
  13. wireshark教程
  14. Python学习入门基础教程(learning Python)--5.6 Python读文件操作高级
  15. POJ 1789 Truck History(Prim+邻接矩阵)
  16. C#单元测试,带你入门
  17. 【机器学习】彻底搞懂CNN
  18. hdu 5119(2014北京)
  19. #一周五# VS2015 CTP6, TFS2015 CTP1更新,老衣的开发工具汇总,2015 MVP 社区巡讲
  20. June. 25th 2018, Week 26th. Monday

热门文章

  1. 解决thymeleaf严格html5校验的方法
  2. python学习之j进程和线程:
  3. Azkaban是什么?(一)
  4. Unity AssetBundle笔记
  5. WebService学习之旅(四)Apache Axis2的安装
  6. uvm_comps.svh
  7. winform中显示标题,点击打开链接
  8. Android学习总结(六)———— 发送自定义广播
  9. Spring 配置定时器(注解+xml)方式—整理
  10. POJ 1741 Tree (树的分治,树的重心)