美好的一天!我在标签栏中放了一张图片,但它的尺寸有误。帮我解决问题。我想填满整个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];
}
我解决了这个问题,你需要正确计算图像;
+ (UIImage *)imageWithColorUIColor *)color andSizeCGSize)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;
}
关于ios - 尺寸设置错误 SelectionIndicatorImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23952693/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |