一.简单介绍下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];