UITabBarController作为一个集合视图控制器,在很多APP上面都会用到。
其视图层级为:
视图层级.png
设置子控件
使用 viewControllers 属性设置
-(UITabBarController *)setRootVCIsTabBarC{
UITabBarController *tabBarC = [UITabBarController new];
UIViewController *vc1 = [UIViewController new];
vc1.tabBarItem.title = @"主页";
// 默认图标
vc1.tabBarItem.image = [UIImage new];
// 选中图标
vc1.tabBarItem.selectedImage = [UIImage new];
UIViewController *vc2 = [UIViewController new];
vc2.tabBarItem.title = @"个人";
tabBarC.viewControllers = @[vc1, vc2];
return tabBarC;
}
使用 setViewControllers: animated: 方法设置
-(UITabBarController *)setRootVCIsTabBarC{
UITabBarController *tabBarC = [UITabBarController new];
UIViewController *vc1 = [UIViewController new];
vc1.tabBarItem.title = @"主页";
// 默认图标
vc1.tabBarItem.image = [UIImage new];
// 选中图标
vc1.tabBarItem.selectedImage = [UIImage new];
UIViewController *vc2 = [UIViewController new];
vc2.tabBarItem.title = @"个人";
[tabBarC setViewControllers:@[vc1, vc2] animated:YES];
return tabBarC;
}
网友评论