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的属性进行隐藏。

(转)自定义UITabBar的更多相关文章

  1. 自定义UITabBar的两种方式

    开发中,经常会遇到各种各样的奇葩设计要求,因为apple提供的UITabBar样式单一,只是简单的"图片+文字"样式,高度49又不可以改变.自定义UITabBar成为了唯一的出路. ...

  2. iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)

    自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...

  3. ios基础篇(九)——自定义UITabBar

    上一篇讲到了UITabBarViewController,接着说说UITabBarViewController中怎么自定义TabBar. 今天仿写了微博,发现底部tabbar中间的button和其他有 ...

  4. 关于iOS自定义UITabBar的几种方法

    作为iOS开发最常用的两个多视图控制器 NavigationController 和 TabBarController 已经很强大了,基本上在大部分的应用中都能看到它们的影子.但是在使用的过程中,系统 ...

  5. iOS项目——自定义UITabBar与布局

    在上一篇文章iOS项目——基本框架搭建中,我们详细说明了如何对TabBarItem的图片属性以及文字属性进行一些自定义配置.但是,很多时候,我们需要修改TabBarItem的图片和文字属性之外,还需要 ...

  6. UITabBarController中自定义UITabBar

    1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...

  7. iOS中 UITabBarController中自定义UITabBar

    1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...

  8. iOS 自定义UITabBar

    推荐一篇非常好的集成各种UITabBar的三方库 <点击这里直取demo> 另外一篇根据runtime定制了一款可以出轨的UITarBar <Runtime实战之定制TabBarIt ...

  9. 利用kvc对UITabBar上的UITabBarButton的尝试修改.md

    一.前言 一次比较懒的想法,不想自定义UITabBar,也不想用第三方框架,于是想尝试修改苹果私有类来达到部分效果 效果如下 点击tabBar 上的按钮,图片有变大再变小的动画 tabBar 上某个按 ...

随机推荐

  1. .NET 基础 一步步 一幕幕 [.NET基础知识点]

    .NET基础知识点   l  .Net平台  .Net FrameWork框架   l  .Net FrameWork框架提供了一个稳定的运行环境,:来保障我们.Net平台正常的运转   l  两种交 ...

  2. CATIA 各个版本代号详解

    一. 第几代(V-"version")简介 1982—1988年,catia相继发布了第一代—V1版本.第二代—V2版本.第三代—V3版本,并于1993年发布了功能强大的第四代—V ...

  3. 114 Flatten Binary Tree to Linked List 二叉树转换链表

    给定一个二叉树,使用原地算法将它 “压扁” 成链表.示例:给出:         1        / \       2   5      / \   \     3   4   6压扁后变成如下: ...

  4. Top-Down和Bottom-Up位图的区别

    Top-Down vs. Bottom-Up DIBs If you are new to graphics programming, you might expect that a bitmap w ...

  5. StarUML安装与Win7不兼容解决

    最近在学习建模工具(StarUML)发现 其他功能一切正常 但是无法显示代码导出功能, 正常界面如下: 我的安装确没有导出功能缺少C++,C# ,Java等导出功能 解决办法:     到StarUM ...

  6. Objective-C Composite Objects

    We can create subclass within a class cluster that defines a class that embeds within it an object. ...

  7. url各部分组成分解

    url各部分组成分解介绍:关于url可能大家都不陌生,第一印象就是网址.但是深究起来,不少朋友并明白里面的一些细节,下面就来进行一下分解.scheme://host:port/path?query#f ...

  8. RStudio的Markdown

    Title This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages ...

  9. com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /192.168.1.13:20881, cause: Failed to bind to: /0.0.0.0:20881

    抛出的异常如上,解决方案是:根据异常信息确定是端口被占用,排查项目是否启动之后没有关闭,在windows命令行中运行如下命令:netstat -ano 检查端口占用的情况,根据pid在任务管理器中杀死 ...

  10. HDU 4347 The Closest M Points (kdTree)

    赤果果的kdTree. 学习传送门:http://www.cnblogs.com/v-July-v/archive/2012/11/20/3125419.html 其实就是二叉树的变形 #includ ...