UITabBarController实现

一.简单介绍下UITabBarController

UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例子就是QQ、微信等应⽤。

二.使用步骤——
*1.使用步骤:
(1)初始化UITabBarController
(2)设置UIWindow的rootViewController为UITabBarController
(3)创建相应的子控制器(viewcontroller)
(4)把子控制器添加到UITabBarController*
2.代码实现

//实例化windows
    self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
  //设置背景颜色为银色
    self.window.backgroundColor=[UIColor grayColor];
 //实例化UITabBarController并将UITabBarController设置为根视图
    UITabBarController *tabC=[[UITabBarController alloc]init];
    self.window.rootViewController=tabC;
// 创建多个子视图,并设置只视图的属性
    UIViewController *one=[[UIViewController alloc]init];
    one.view.backgroundColor=[UIColor yellowColor];
    //设置itmen显示的文字
    one.tabBarItem.title=@"主页";
    //设置item上的图片
    one.tabBarItem.image=[UIImage imageNamed:@"home.png"];
    //设置显示消息的提示个数
    one.tabBarItem.badgeValue = @"12";

    UIViewController *two=[[UIViewController alloc]init];
    two.view.backgroundColor=[UIColor blueColor];
    //设置item显示的文字
    two.tabBarItem.title=@"位置";
    two.tabBarItem.image=[UIImage imageNamed:@"Location.png"];
    two.tabBarItem.badgeValue=@"1";

    UIViewController *thress=[[UIViewController alloc]init];
    thress.view.backgroundColor=[UIColor purpleColor];
    thress.tabBarItem.title=@"设置";
    thress.tabBarItem.image=[UIImage imageNamed:@"Setting.png"];

    tabC.viewControllers =@[one,two,thress];
    [self.window makeKeyAndVisible];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值