iOS UIKit - TabBarController

数组。
管理多个控制器,完成控制器之间的切换。

一、使用步骤
1.storyBoard创建

2.代码创建
(1)创建UIWindow
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

(2)初始化UITabBarController
UITabBarController *tb=[[UITabBarController alloc]init];

(3)设置UIWindow的rootViewController为UITabBarController
self.window.rootViewController=tb;

(4)创建相应的子控制器(viewcontroller)
UIViewController *c1=[[UIViewController alloc]init];
c1.view.backgroundColor=[UIColor grayColor];
c1.view.backgroundColor=[UIColor greenColor];
c1.tabBarItem.title=@”消息”;
c1.tabBarItem.image=[UIImage imageNamed:@”tab_recent_nor”];
c1.tabBarItem.badgeValue=@”123”;
UIViewController *c2=[[UIViewController alloc]init];
c2.view.backgroundColor=[UIColor brownColor];
c2.tabBarItem.title=@”联系人”;
c2.tabBarItem.image=[UIImage imageNamed:@”tab_buddy_nor”];
UIViewController *c3=[[UIViewController alloc]init];
c3.tabBarItem.title=@”动态”;
c3.tabBarItem.image=[UIImage imageNamed:@”tab_qworld_nor”];
UIViewController *c4=[[UIViewController alloc]init];
c4.tabBarItem.title=@”设置”;
c4.tabBarItem.image=[UIImage imageNamed:@”tab_me_nor”];

(5)把子控制器添加到UITabBarController
(5.1)第一种方式
[tb addChildViewController:c1];
[tb addChildViewController:c2];

(5.2)第二种方式
tb.viewControllers=@[c1,c2,c3,c4];
(6)显示Window
[self.window makeKeyAndVisible];

二、基本属性

1.UITabBar
工具条称为UITabBar ,如果UITabBarController有N个子控制器,那么UITabBar内部就会有N 个UITabBarButton作为子控件与之对应。UITabBarButton在UITabBar中得位置是均分的,UITabBar的高度为49。

2.UITabBarButton
UITabBarButton画面显示什么内容,由对应子控制器的tabBarItem属性来决定
c1.tabBarItem.title=@”消息”;
c1.tabBarItem.image=[UIImage imageNamed:@”tab_recent_nor”];

三、代码示例

四、总结

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值