TabBar
UITabBarContoller显示屏幕底部出现几个标签来管理不同视图。如图:
使用步骤:
- 初始化UITabBarController
UITabBarController *tb = [[UITabBarController alloc]init];
- 设置UIWindow的rootViewController
self.window.rootViewController = tb;
- 创建相应的子视图(UIViewController)
UIViewController *c1 = [[UIViewController alloc]init];
c1.view.backgroundColor = [UIColor grayColor];
c1.tabBarItem.title = @"消息";
c1.tabBarItem.image = [UIImage imageNamed:@"first_normal"];
c1.tabBarItem.badgeValue = @"12";
UIViewController *c2 = [[UIViewController alloc]init];
c2.view.backgroundColor = [UIColor yellowColor];
c2.tabBarItem.title = @"联系人";
c2.tabBarItem.image = [UIImage imageNamed:@"first_normal"];
- 把子视图加入到TabBarController
tb.viewControllers = @[c1, c2];
- 显示
[self.window makeKeyAndVisible];
- tabBarItem图标选中后修改图片
c1.tabBarItem= [ c1.tabBarItem initWithTitle:@"小时"
image:[UIImage imageNamed:@"second_normal"] //未选中时到图片
selectedImage:[UIImage imageNamed:@"second_selected"]];]//选中时到图片