本文介绍了错误的大小 setSelectionIndicatorImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天!我在标签栏中放了一张图片,但它的尺寸错误.帮我解决问题.我想填满整个Item.
Good day! I put a picture in a tab bar but it has wrong sizes. Help me solve the problem.I want to fill the entire Item.
+ (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];
}
推荐答案
我解决了这个问题你需要正确计算图像;
I solved this problem you need to properly calculate image;
+ (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;
}
这篇关于错误的大小 setSelectionIndicatorImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!