ios - resizableImageWithCapInsets 图片总是错位?

标签 ios uikit core-graphics

是否可以创建具有可调整大小图像的正确对齐 UIImageView?

我尝试了所有方法(例如图像的二次方等),但无法正常工作。

UIImageView的坐标是:

po _Background

(UIImageView *) $1 = 0x14c42bd0 
<UIImageView: 0x14c42bd0;
frame = (16 38; 992 672);
opaque = NO;
autoresize = LM+RM+TM+BM;
userInteractionEnabled = NO;
layer = <CALayer: 0x14c42ba0>> - (null)

UIImage 本身是 96x96(视网膜,即 png 是 192x192,比例为 2)。可调整大小的 UIImage 是使用以下方法创建的:

UIEdgeInsets edgeInsets = UIEdgeInsetsMake(32, 32, 32, 32);
UIImage* resizableImage = [originalImage resizableImageWithCapInsets:edgeInsets];
[_Background setImage:resizableImage];

在模拟器中打开“颜色未对齐图像”时,UIImageView _Background 以黄色突出显示。在调试器中删除它的 UIImage:

[_Background setImage:nil];

删除黄色高亮,即没有图像 -> 没有错位。

有人知道发生了什么以及我如何确保它对齐吗?

谢谢。

最佳答案

根据这个答案:What does yellow tinting represent when using "color misaligned images" on iPhone/iOS ,黄色突出显示表示图像被拉伸(stretch)。由于这就是您对可调整大小的图像的要求,因此情况总是如此是有道理的。

关于ios - resizableImageWithCapInsets 图片总是错位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14415821/

相关文章:

ios - 在项目结构中找不到 Storyboard中的自定义 View Controller

ios - video.js:自动点击播放按钮(绕过 iOS 自动播放限制)

ios - UIStoryboardSegue & UIVisualEffectView - 完成 block 退出后模糊效果丢失

ios - 在 CGContext 中绘制透明 PNG 显示为黑色

ios - UIBezierPath 和 NSBezierPath 在绘制圆弧时产生不同的结果

ios - UItableview 有两组选项

ios - 如何将日期合并到字典中?

ios - 在 UIPickerView 中更改选定行的颜色,滚动时也是如此

ios - 为什么应用程序包并不总是一个包?

ios - 画一个实心半圆