UITabBarController是IOS中很常用的一个viewController。UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的container viewController中.

一.创建

最常见的创建UITabBarController的地方就是在application delegate中的 applicationDidFinishLaunching:方法,因为UITabBarController通常是作为整个程序的rootViewController的,我们需要在程序的window显示之前就创建好它,具体步骤如下:

  1、创建一个UITabBarController对象

  2、创建tabbarcontroller中每一个tab对应的要显示的对象子控制器

  3、通过设置UITabBarController对象为window.rootViewController,然后显示window

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//创建窗口

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

//创建tabbarcontroller

UITabBarController * tabbarController = [[UITabBarController alloc]init];

tabbarController.tabBar.tintColor = [UIColor orangeColor]; //显示的字体颜色

//创建每个界面

HomeViewController * homeVC =[[HomeViewController alloc]init];

homeVC.view.backgroundColor =[UIColor whiteColor];

homeVC.tabBarItem = [[UITabBarItem alloc]initWithTitle: @"主页"image:[UIImage imageNamed:@"tabbar_home"] selectedImage:[[UIImage imageNamed:@"tabbar_home_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];//使用自身的颜色,而不是默认颜色

//将创建的添加到tabbarController

tabbarController.viewControllers = @[homeVC,messVC,discVC,myVC];//加的顺序就是现实的顺序

self.window.rootViewController = tabbarController;

//显示窗口

[self.window makeKeyAndVisible];

return YES;

}

二.tabbar

屏幕下方的工具条称为UITabBar ,如果UITabBarController有N个子控制器,那么UITabBar内部就会有N 个UITabBarButton作为子控件与之对应。

注意:UITabBarButton在UITabBar中得位置是均分的,UITabBar的高度为49。

三.UITabBarButton

UITabBarButton⾥面显⽰什么内容,由对应子控制器的tabBarItem属性来决定

homeVC.tabBarItem.title=@"消息";

四.在tabbar中间加入一个按钮

第一步:自己定义一个CustomTabBarController,一个CustomUITabBar

第二步:CustomUITabBar中重新布局(给button让出一个位置)

- (void)layoutSubviews{

[super layoutSubviews];

//计算每个item的平均宽度

CGFloat avgWith = self.frame.size.width/5;

NSInteger index = 0;

for (UIView *item in self.subviews) {

if ([item isKindOfClass:NSClassFromString(@"UITabBarButton")]) {

item.frame = CGRectMake(index * avgWith, item.frame.origin.y, avgWith, item.frame.size.height);

index ++;

if (index == 2) {

_addButton.frame = CGRectMake(index * avgWith, 3, avgWith, 44);

[self addSubview:_addButton];//加入button

index++;

}

}

}

}

CustomTabBarController和CustomUITabBar之间是代理关系,而tabbar是只读属性,用下面的话来设置

@implementation CustomTabBarController

- (void)viewDidLoad {

[super viewDidLoad];

CustomUITabBar *tb = [[CustomUITabBar alloc]init];

tb.delegate = self;

[self setValue:tb forKey:@"tabBar"];//只读,属性设置不了的时候

}

第三步:实现代理

代理实现点击button打开页面

– presentViewController:animated:completion: 弹出一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil
– dismissViewControllerAnimated:completion:退出一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil

-(void)addButtonDidClicked:(UIButton *)sender{

addViewController * addVC = [[addViewController alloc]init];

addVC.view.backgroundColor = [UIColor whiteColor];

[self presentViewController:addVC animated:YES completion:nil];

}

UITabBarController+微博简单模拟1的更多相关文章

  1. java web学习总结(二十二) -------------------简单模拟SpringMVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

  2. WPF简单模拟QQ登录背景动画

    介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...

  3. Linux 内核 链表 的简单模拟(2)

    接上一篇Linux 内核 链表 的简单模拟(1) 第五章:Linux内核链表的遍历 /** * list_for_each - iterate over a list * @pos: the & ...

  4. Linux 内核 链表 的简单模拟(1)

    第零章:扯扯淡 出一个有意思的题目:用一个宏定义FIND求一个结构体struct里某个变量相对struc的编移量,如 struct student { int a; //FIND(struct stu ...

  5. JavaWeb学习总结(四十九)——简单模拟Sping MVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

  6. 简单模拟Hibernate的主要功能实现

    在学习期间接触到Hibernate框架,这是一款非常优秀的O/R映射框架,大大简化了在开发web项目过程中对数据库的操作.这里就简单模拟其底层的实现. /*******代码部分,及其主要注解***** ...

  7. 【HDU 4452 Running Rabbits】简单模拟

    两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时).初始方向dir(E.N.W.S)和左转周期turn(小时/次). 各自每小时往 ...

  8. Jquery源码分析与简单模拟实现

    前言 最近学习了一下jQuery源码,顺便总结一下,版本:v2.0.3 主要是通过简单模拟实现jQuery的封装/调用.选择器.类级别扩展等.加深对js/Jquery的理解. 正文 先来说问题: 1. ...

  9. (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数<=3,输出剩下的人 )

    题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

随机推荐

  1. 部分GDAL工具功能简介

    主要转自http://blog.csdn.net/liminlu0314?viewmode=contents 部分GDAL工具功能简介 gdalinfo.exe 显示GDAL支持的各种栅格文件的信息. ...

  2. System.Speech.Synthesis 添加暂停、继续功能

    为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...

  3. json的js和C#操作

    C#端的WebService接口接收json格式数据,处理后以json格式返回result using System; using System.Collections.Generic; using ...

  4. 学习使用Vim(二)——User Manuals, Getting Started

    Vim的用户手册主要包含以下三个部分:     Getting Started;     Editing Effectively;     Tuning Vim;     分别代表基本编辑技巧,更优化 ...

  5. ios10 适配问题总结

    看各个大神整理而成 1.检查版本问题 不可以像下面这样用 #define isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringTo ...

  6. VS2015预览版中的C#6.0 新功能(一)

    VS2015预览版中的C#6.0 新功能(二) VS2015预览版中的C#6.0 新功能(三) VS2015的预览版在11月12日发布了,下面让我们来看看C#都提供了哪些新的功能. 字符串添写(Str ...

  7. (转)Ubuntu中让终端对于历史输出的内容保持足够长

    原地址:http://www.crifan.com/ubuntu_terminal_make_retain_long_enough_history_output_content/ Ubuntu下用终端 ...

  8. Hibernate事务传播性

    事务的几种传播特性 1. PROPAGATION_REQUIRED: 如果存在一个事务,则支持当前事务.如果没有事务则开启 比如说:在UserManager中addUser里开启了,那么在addLog ...

  9. [Head First Python]4. pickle.dump pickle.load

    sketch.py #--*-- coding:utf-8 --*-- import pickle import nester man = [] other = [] try: data = open ...

  10. load average[zhuan]

    load average值的含义 单核处理器 假设我们的系统是单CPU单内核的,把它比喻成是一条单向马路,把CPU任务比作汽车.当车不多的时候,load <1:当车占满整个马路的时候 load= ...