ios - 尺寸设置错误 SelectionIndicatorImage
<p><p>美好的一天!我在标签栏中放了一张图片,但它的尺寸有误。帮我解决问题。我想填满整个Item。</p>
<pre><code>+ (void)setupTabBarAppearance
{
[ setBarTintColor:];
UIImage *image = [] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 1, 2) resizingMode:UIImageResizingModeStretch];
[ setSelectionIndicatorImage:image];
}
</code></pre>
<p> <img src="/image/YxQE7.png" alt="enter image description here"/> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我解决了这个问题,你需要正确计算图像; </p>
<pre><code>+ (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);
;
UIRectFill(rect); // Fill it with your color
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 尺寸设置错误 SelectionIndicatorImage,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23952693/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23952693/
</a>
</p>
页:
[1]