iOS开发之UITabBarController

UITabBarController.png

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;
    
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,033评论 3 119
  • William_Wei007阅读 219评论 0 0
  • “嗷……”白狼双双倒地,痛苦地挣扎起来,口中呜咽不断,没一会儿便化为血水消失无踪!“切,畜牲!”北凝霜一把扯下脸上...
    安月雨香阅读 233评论 0 0
  • 蜗居一角 风吹雨打 一夏未见 青苔褪却 木耳染墙 红色的茑萝松 星 星的天使 清风抖动衣裳 望着青蓝的天空 不置一...
    白里浪阅读 157评论 0 0
  • 文/白茶心 这是一个黄昏的夜晚,米沙又回到了家乡。这个时候,西边的天空还残留着夕阳的余晖,西南边却是乌云滚滚,想要...
    白茶心阅读 289评论 6 5