首页 > 其他 > 详细

UITabBarController

时间:2015-11-26 22:40:02      阅读:182      评论:0      收藏:0      [点我收藏+]

UITabBarController

UITabBarControllerUINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换

1、         创建UITabBarController对象

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

2、         创建相应的子控制器

ViewController *vc = [[ViewController alloc] init];

vc.tabBarItem.title = @"主页";//设置标题

vc.tabBarItem.image = [UIImage imageNamed:@"1"];//设置图片

FirstViewController *first = [[FirstViewController alloc] init];

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

first.tabBarItem.image = [UIImage imageNamed:@"2"];

3、         把子视图控制器加入UITabbarController

     tabbar.viewControllers = @[vc,first];

4、         设置windowrootViewControllerUITabbarController

self.window.rootViewController = tabbar

5、         设置tabbarVC选中第几个子视图:

[self.tabBarController setSelectedIndex:2];

6、         跳到某个指定的VC

UIViewController *vc = [self.tabBarController.viewControllers objectAtIndex:1];

[self.tabBarController setSelectedViewController:vc];

7、         获取当前选中的下标:

NSInteger index= self.tabBarController.selectedIndex;

8、         标签栏信息提示:

first.tabBarItem.badgeValue = @"3";

9、         设置选中的颜色(图片、文字)

 tabbar.tabBar.tintColor = [UIColor greenColor];

10、     设置背景图:

tabbar.tabBar.backgroundImage = [UIImage imageNamed:@"buy_ex"];

11、     设置背景色

tabbar.tabBar.barTintColor = [UIColor brownColor];

12、   置选中、未选中的图片

UIImage *image=[[UIImage imageNamed:@"3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

UIImage *image2 =[[UIImage imageNamed:@"tabbar_profile_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

second.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"个人" image:image selectedImage:image2];

 

UITabBarController

原文:http://www.cnblogs.com/niliu-star/p/4998886.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!