UITabBarController 详解

  // UITabBarController 标签视图控制
    // 主要管理没有层级关系的视图控制器
    // 1. ViewControllers 所有被管理的视图控制器, 都在这个数组中
    // 2. set
    // 可以通过setter方法去赋值
    //也可以通过下述方法进行视图控制器数组赋值
    // 3. 通过一个数组创建完成后, 如果数组中的控制器没有设置tabbarItem, 则显示一个空的tabbaritem
    // 4. tabbarItem 根据自己需求去创建对应的tabbarItem
    // ViewController的属性, (Category)
    // 注: 因为没有视图控制器的tabBarItem都不一样, 因此不能设为TabBarController的属性
    
    // tabbarItem 的创建方式
    // 1> initWithTabBarSystemItem:tag 根据系统样式去处理
    // 2> initWithTitle:iamge:tag: 根据自定义图片去创建
    // 3> initWithTitle:image:selectedImage:tag: 根据自定义的图片和的文字去创建
    
    // 一般不要超过5个
    
    // 6.tabbar (bar的高度: 49)
    // 1> barTintColor bar 的背景色
    // 2> tintColor bar上元素的颜色
    // 3> translucent bar 是否透明
    // 3> badgeValue 角标
    // 7. appearance 全局设置
    //   设置bar上字体和png图的颜色
    [[UITabBar appearance] setTintColor:[UIColor blueColor]];
    //   设置bar的整个背景的颜色
    [[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
    UITabBarController *tabbar = [[UITabBarController alloc] init];
    
    ViewController *vc1 = [[ViewController alloc] init];
    vc1.view.backgroundColor = [UIColor whiteColor];
    UINavigationController *navc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    // 修改系统标题颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor purpleColor]}];
    //   *********************************************
    // 设置tabbaritem时, 给你要放进数组中的控制器去设置
    // Bar的标题
    navc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"xinwen" image:nil tag:0];
    // 当前导航栏的标题
    vc1.navigationItem.title = @"news";
    [tabbar setViewControllers:@[navc1]];
    // 设置透明度
    // tabbar.tabBar.translucent = NO;
    _window.rootViewController = tabbar;

运行效果图:

原文地址:https://www.cnblogs.com/mafeng/p/5698862.html