(转)自定义UITabBar
push页面时,可调用hidesBottomBarWhenPushed进行隐藏。
第一步,我们需要一些图片:
各个选项的图标和tabbar的背景图片,最后还要一个透明的1x1像素的图片。
第二步,新建一个工程,在工程内建一个继承于UITabBarController的类。
第三步,首先写一个方法,返回一个UINavigationController
- -(UINavigationController*) viewControllerWithTitle:(NSString*) title image:(UIImage*)image
- {
- UIViewController* viewController = [[UIViewController alloc] init];
- viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
- viewController.title = title;
- UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
- return nav;
- }
然后在viewDidLoad里面创建TabbarController的viewControllers
- self.viewControllers = [NSArray arrayWithObjects:
- [self viewControllerWithTitle:@"1" image:IMG(@"1")],
- [self viewControllerWithTitle:@"2" image:IMG(@"2")],
- [self viewControllerWithTitle:nil image:nil],
- [self viewControllerWithTitle:@"3" image:IMG(@"3")],
- [self viewControllerWithTitle:@"4" image:IMG(@"4")], nil nil];
看到没有,比较猥琐的就是第三个ViewController什么都没设置。
因为我们要在那个位置放一个自己的按钮,继续在viewDidLoad写:
- UIButton* button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 65, 65)];
- button.center = CGPointMake(160, 20);
- [button setBackgroundImage:IMG(@"add") forState:UIControlStateNormal];
- [button addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
- [self.tabBar addSubview:button];
然后设置背景图片:
- [self.tabBar setBackgroundImage:IMG(@"tabbarbg")];
运行之后是这样的:
会发现按钮上面有一条横线,然后再设置这个阴影运行后就没有人发现你猥琐的行径。
- [self.tabBar setShadowImage:IMG(@"transparent")];
最后效果图(iOS7和iOS6):
这样做的好处:
在ViewController里push页面的时候可调用hidesBottomBarWhenPushed的属性进行隐藏。
(转)自定义UITabBar的更多相关文章
- 自定义UITabBar的两种方式
开发中,经常会遇到各种各样的奇葩设计要求,因为apple提供的UITabBar样式单一,只是简单的"图片+文字"样式,高度49又不可以改变.自定义UITabBar成为了唯一的出路. ...
- iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)
自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...
- ios基础篇(九)——自定义UITabBar
上一篇讲到了UITabBarViewController,接着说说UITabBarViewController中怎么自定义TabBar. 今天仿写了微博,发现底部tabbar中间的button和其他有 ...
- 关于iOS自定义UITabBar的几种方法
作为iOS开发最常用的两个多视图控制器 NavigationController 和 TabBarController 已经很强大了,基本上在大部分的应用中都能看到它们的影子.但是在使用的过程中,系统 ...
- iOS项目——自定义UITabBar与布局
在上一篇文章iOS项目——基本框架搭建中,我们详细说明了如何对TabBarItem的图片属性以及文字属性进行一些自定义配置.但是,很多时候,我们需要修改TabBarItem的图片和文字属性之外,还需要 ...
- UITabBarController中自定义UITabBar
1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...
- iOS中 UITabBarController中自定义UITabBar
1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...
- iOS 自定义UITabBar
推荐一篇非常好的集成各种UITabBar的三方库 <点击这里直取demo> 另外一篇根据runtime定制了一款可以出轨的UITarBar <Runtime实战之定制TabBarIt ...
- 利用kvc对UITabBar上的UITabBarButton的尝试修改.md
一.前言 一次比较懒的想法,不想自定义UITabBar,也不想用第三方框架,于是想尝试修改苹果私有类来达到部分效果 效果如下 点击tabBar 上的按钮,图片有变大再变小的动画 tabBar 上某个按 ...
随机推荐
- 转 11g Grid Control: Overview of the EMCTL Options Available for Managing the Agent
1.概念: The Enterprise Manager DBConsole consists of the following components: - A Standalone OC4J Man ...
- D - 連結 / Connectivity 并查集
http://abc049.contest.atcoder.jp/tasks/arc065_b 一开始做这题的时候,就直接蒙逼了,n是2e5,如果真的要算出每一个节点u能否到达任意一个节点i,这不是f ...
- 自己项目中PHP常用工具类大全分享
<?php /** * 助手类 * @author www.shouce.ren * */ class Helper { /** * 判断当前服务器系统 * @return string */ ...
- 如何正确在IDEA 里maven构建的项目中引入lib的jar包(图文详解)
不多说,直接上干货! 问题详情 以下是我,maven构建出来的最新spark2.2.0-bin-hadoop2.6的项目. 有些依赖包,maven还是无法一次性满足,所以,得手动加入lib的jar包. ...
- sgu316Kalevich Strikes Back(线段树+扫描线)
做法:总体想法是求出一个矩形的面积以及它所包含的矩形,然后用自己的面积减掉所包含的.主要问题是怎样求解它所包含的矩形. 因为是没有相交点的,可以利用扫描线的方法去做,类似染色,当前段如果是x色,也就是 ...
- Mongodb JAVA API
连接mongodb 1.连接一个mongodb ); 2.连接mongodb集群 MongoClient mongoClient = ), new ServerAddress("localh ...
- 洛谷[LnOI2019]长脖子鹿省选模拟赛t1 -> 快速多项式变换
快速多项式 做法:刚拿到此题有点蒙,一开始真没想出来怎么做,于是试着去自己写几个例子. 自己枚举几种情况之后就基本看出来了,其实本题中 n 就是f(m)在m进制下的位数,每项的系数就是f(m)在m进制 ...
- [Luogu1343]地震逃生 最大流
题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...
- Objective-C Log Handling
NSLog method In order to print logs, we use the NSLog method in Objective-C programming language whi ...
- mysqldumpslow及explain使用简介