| 本帖最后由 竹林风 于 2018-12-2 16:37 编辑 
 demo 演示
 
 
   
 AppDelegate设置
 
 
 
 [Objective-C] 纯文本查看 复制代码 //创建并初始化UITabBarController
    MyTabBarController *tabBarController = [[MyTabBarController alloc]init];
    self.window.rootViewController = tabBarController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
 MyTabBarController代码设置
 
 
 [C#] 纯文本查看 复制代码 //初始化两个视图控制器
    firstVC *first = [firstVC new];
    SecondVC *second = [SecondVC new];
    
    //设置控制器图片(使用UIImageRenderingModeAlwaysOriginal,不被系统渲染成蓝色)
    first.tabBarItem.image = [[UIImage imageNamed:@"home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    first.tabBarItem.selectedImage = [[UIImage imageNamed:@"home_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    second.tabBarItem.image = [[UIImage imageNamed:@"mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    second.tabBarItem.selectedImage = [[UIImage imageNamed:@"mine_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //设置tabbarController 文字选中颜色(默认渲染为蓝色)
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    
    //创建一个数组包含两个控制器
    NSArray *aryVC = @[first,second];
    
    //将数组传递给TabbarController
    self.viewControllers = aryVC;
 附件:
  Test-TabBarController.zip
(99.96 KB, 下载次数: 10) |