以下代码是在TabBarViewController的ViewControllers的其中一个ViewController的viewDidLoad中写的!!!
UIImage *image = [UIImage imageNamed:@"Heart"];
//item未选中状态时,image不使用tintColor的颜色
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//添加tabbarItem
UITabBarItem *tabbarItem = [[UITabBarItem alloc] initWithTitle:@"育儿搜" image:image selectedImage:image];
//设置item未选中状态时,title的颜色
[tabbarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
self.tabBarItem = tabbarItem;
时间: 2024-10-27 00:22:19