iPhone stretchableImageWithLeftCapWidth 只生成“D" [英] iPhone stretchableImageWithLeftCapWidth only makes "D"s

查看:9
本文介绍了iPhone stretchableImageWithLeftCapWidth 只生成“D"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIImage *aImage = [[UIImage imageNamed:@"Gray_Button.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:0];

尝试制作玻璃丸按钮".

Trying to make a "glass pill button".

如果图像更大……而我尝试使用它的按钮……更小,拉伸"会做什么?

What does "stretch" do if the image is bigger... and the button I'm trying to use it on... is smaller?

图像会拉伸"和收缩"吗?

Does the image 'stretch' and 'shrink'?

我问的原因...是因为我所有的图像最终看起来都像D"形.

The reason I ask... is because all my images end up look like a "D" shape.

左边是方形的……右边是圆形的.

The left side is squared-off... and the right side is rounded.

D 形会告诉你我做错了什么?太多……或太少……leftCap 设置"?图片太大?

What would a D-shape tell you that I'm doing wrong? Too much.. or too little... "leftCap setting"? Too large an image?

推荐答案

如果 leftCapWidthtopCapHeight 均非零,则可拉伸图像分为 9 部分.

A stretchable image is divided into 9 parts, if both leftCapWidth and topCapHeight are nonzero.

     leftCapWidth
      <----->
      +--------------+ ^
      |     | |      | |
      |  A  | |  B   | | topCapHeight
      |-----+·+------| v
      |-----+·+------|
      |  C  | |  D   |
      |     | |      |
      +--------------+

中心部分的大小始终为1 px,这是被拉伸的部分,例如:

The central parts are always 1 px in size, and this is the part that is stretched, for example:

     leftCapWidth (constant!)
      <----->
      +------------------+ ^
      |     |     |      | |
      |  A  |     |  B   | | topCapHeight (constant!)
    v |-----+ - - +------| v
    | |     .     .      |
    | |     .     .      |
    ^ |-----+ - - +------|
      |  C  |     |  D   |
      |     |     |      |
      +------------------+
            >-----<
        stretched region

要创建一个玻璃药丸按钮",您应该将圆形边框填充到上面的区域 A、B、C 和 D,并将该药丸的半径提供给 leftCapWidth 和 <代码>topCapHeight.

To create a "glass pill button", you should fill the rounded border into the regions A, B, C and D above, and supply the radius of that pill into both the leftCapWidth and topCapHeight.

此外,可拉伸图像不可收缩.如果您尝试使用比您想要应用的按钮(或其他任何东西)更大的可拉伸图像,它们可能会被错误地渲染(尤其是在较旧的 iOS 上).

Also, a stretchable image is not shrinkable. If you try to use stretchable images bigger than the buttons (or whatever else) you want to apply it to, they may be rendered incorrectly (especially on older iOSes).

这篇关于iPhone stretchableImageWithLeftCapWidth 只生成“D"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆