设置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;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 深入理解 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 构建精确任务处理应用