美好的一天!我在标签栏中放了一张图片,但尺寸错误。帮我解决问题。我想填写整个项目。
+ (void)setupTabBarAppearance
{
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:30.0f/255.0f green:201.0f/255.0f blue:224.0f/255.0f alpha:1]];
UIImage *image = [[self imageWithColor:[UIColor colorWithRed:255.0f/255.0f green:198.0f/255.0f blue:25.0f/255.0f alpha:1]] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 1, 2) resizingMode:UIImageResizingModeStretch];
[[UITabBar appearance] setSelectionIndicatorImage:image];
}
答案 0 :(得分:2)
我解决了这个问题,你需要正确计算图像;
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
CGRect rect = CGRectMake(0, 0, size.width, size.height); // <- Here
// Create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect); // Fill it with your color
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
答案 1 :(得分:0)
尝试以下代码
尝试以下方法:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
要为非活动按钮着色,请将以下代码放入VC的viewDidLoad中:
UITabBarItem *tabBarItem = [yourTabBarController.tabBar objectAtIndex:0];
UIImage *unselectedImage = [UIImage imageNamed:@"icon-unselected"];
UIImage *selectedImage = [UIImage imageNamed:@"icon-selected"];
[tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem setSelectedImage: selectedImage];
您需要为所有tabBarItem执行此操作, 希望这会奏效。