StretchableImageWithLeftCapWidth 拉伸错误的部分

发布于 2024-09-04 15:06:34 字数 351 浏览 2 评论 0原文

我正在尝试使用带有可拉伸图像的 UIImageWithLeftCapWidth 来设置 UIImageView 中的图像,但遇到了一个奇怪的缩放错误。基本上将我的图像想象成一个 31 像素宽的椭圆形。左右 15 个像素是上限,中间的单个像素是缩放部分。

如果我将左上限设置为 15,效果很好。但是,如果我将其设置为 4,我希望得到一个有点弯曲的“中心”部分,因为它跨越中心,而两端有点弯曲捏。

我得到的是左端盖似乎是正确的,后面是一个长的中间部分,就好像我在像素 5 处缩放了单个像素一样,然后是图像右侧的一部分,它在大约两倍的宽度上扩展和闭合原始图像的。生成的图像就像一个温度计灯泡。

有没有人见过这样的奇怪行为并且可能知道发生了什么事?

I am trying to use a UIImage with stretchableImageWithLeftCapWidth to set the image in my UIImageView but am encountering a strange scaling bug. Basically picture my image as an oval that is 31 pixels wide. The left and right 15 pixels are the caps and the middle single pixel is the scaled portion.

This works fine if I set the left cap to 15. However, if I set it to, say, 4. I would expect to get a 'center' portion that is a bit curved as it spans the center while the ends are a little pinched.

What I get is the left cap seemingly correct, followed by a long middle portion that is as if I scaled the single pixel at pixel 5, then a portion at the right of the image where it expands and closes over a width about twice the width of the original image. The resulting image is like a thermometer bulb.

Has anyone seen odd behavior like this and might know what's going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-09-11 15:06:34

你的观察是正确的,乔伊。 StretchableImageWithLeftCapWidth 不会像您期望的那样扩展图像的整个中心。它仅扩展左盖右侧的像素列和顶盖下方的像素行!

使用 UIView 的 contentStretch 属性代替,您的问题将得到解决。这样做的另一个优点是 contentStretch 还可以适当缩小图形,而stretchableImageWithLeftCapWidth 仅在放大图形时才起作用。

Your observation is correct, Joey. StretchableImageWithLeftCapWidth does NOT expand the whole center of the image as you would expect. It only expands the pixel column just right of the left cap and the pixel row just below the top cap!

Use UIView's contentStretch property instead, and your problem will be solved. Another advantage to this is that contentStretch can also shrink a graphic properly, whereas stretchableImageWithLeftCapWidth only works when making the graphic larger.

你另情深 2024-09-11 15:06:34

不确定我是否理解正确,但 LeftCapWidth 等是为圆角设计的,圆角半径内矩形中的所有内容都被拉伸以适应目标按钮等上“大写字母”之间的空间。

因此,如果您的椭圆形比 4 x 2 = 8 更高或更宽,那么中间矩形中的任何内容都会被拉伸。而你的是,所以它至少看起来有点难看!但如果它甚至不对称,则说明某些因素影响了拉伸。也许与原点或框架有关,或者何时设置,或者可能设置了两次,或者您有两个不同的拉伸图像彼此重叠,使温度计看起来如此。

我曾经在同一个地方创建了两个相同的按钮,使用相同的保留对象 - 当然扔掉了前一个按钮。然后我想知道为什么当我将 alpha 设置为 0 时按钮没有消失...但它确实消失了,只是在它下面有一个“死”的相同按钮:)

Not sure if I got you right, but LeftCapWidth etc is made for rounded corners, with everything in the rectangle within the rounding radius is stretched to fit the space between the 'caps' on the destination button or such.

So if your oval is taller or wider than 4 x 2 = 8, whatever is in the middle rectangle will be stretched. And yours is, so it would at least look at bit ugly! But if it's not even symmetrical, something has affected the stretch. Maybe something to do with origin or frame, or when it's set, or maybe it's set twice, or you have two different stretched images on top of each other giving the thermometer look.

I once created two identical buttons in the same place, using the same retained object - of course throwing away the previous button. Then I wondered why the heck the button didn't disappear when I set alpha to 0... But it did, it's just that there was a 'dead' identical button beneath it :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文