设置TabBar图片






设置TabBar图片


复制代码
// 拿到 TabBar 在拿到想应的item
    UITabBar *tabBar = _tabBarController.tabBar;
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
    UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
    // 对item设置相应地图片
    item0.selectedImage = [[UIImage imageNamed:@"sy-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    item0.image = [[UIImage imageNamed:@"sy"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item1.selectedImage = [[UIImage imageNamed:@"fl-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    item1.image = [[UIImage imageNamed:@"fl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item2.selectedImage = [[UIImage imageNamed:@"gwc-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    item2.image = [[UIImage imageNamed:@"gwc"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item3.selectedImage = [[UIImage imageNamed:@"wd-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    item3.image = [[UIImage imageNamed:@"wd"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];


复制代码

 

 

 

//设置tabbar图片和字体

 

 

复制代码
 

    MailViewController  *mailVC = [[MailViewController   alloc]init];
    ClassViewController *classVC = [[ClassViewController alloc]init];
    ShopcarViewController *shopcarVC = [[ShopcarViewController alloc]init];
    MineViewController *mineVC = [[MineViewController alloc]init];
    
    
    UITabBarController *tabbarvc = [[UITabBarController alloc]init];
    tabbarvc.viewControllers  = @[mailVC,classVC,shopcarVC,mineVC];

    mailVC.tabBarItem.title = @"首页";
    classVC.tabBarItem.title = @"分类";
    shopcarVC.tabBarItem.title = @"购物车";
    mineVC.tabBarItem.title = @"我的";
    
    mailVC.tabBarItem.image = [UIImage imageNamed:@"sy@2x.jpg"];
    classVC.tabBarItem.image = [UIImage imageNamed:@"fl@2x.jpg"];
    shopcarVC.tabBarItem.image = [UIImage imageNamed:@"gwc@2x.jpg"];
    mineVC.tabBarItem.image = [UIImage imageNamed:@"wd@2x.jpg"];
    
    
    mailVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"sy01@2x.jpg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    classVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"fl01@2x.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    shopcarVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"gwc01@2x.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"wd01@2x.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
   
    [mailVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected];
    
    [classVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected];
    
    [shopcarVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected];
    
    [mineVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:68/255.0 green:173/255.0 blue:50/255.0 alpha:1]} forState:UIControlStateSelected];
    
    
    
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = tabbarvc;
    
复制代码

 

posted @   OIMMZC  阅读(952)  评论(0编辑  收藏  举报
编辑推荐:
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
阅读排行:
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· 语音处理 开源项目 EchoSharp
· 《HelloGitHub》第 106 期
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 使用 Dify + LLM 构建精确任务处理应用
点击右上角即可分享
微信分享提示