1

参考:iPhone stretchableImageWithLeftCapWidth 只制作“D”

我有一个大小为 的按钮的图像13x30。我想拉伸图像以填充大小为 的按钮45x30

这是我正在使用的代码:

UIImage *shareImage = [[UIImage imageNamed:@"btn_red"] stretchableImageWithLeftCapWidth:16.0f topCapHeight:0.0];
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46.0f, 30.0f)];
etc....

我得到的图像很不正常。我得到的是真实大小的图像,后面有一些较浅的阴影,如图所示按钮

为什么会这样?我完全不明白。我有正确的可拉伸逻辑,并且我遵循了每个人在教程/帖子中所说的内容。

如果我得到一些帮助,我将不胜感激。

4

3 回答 3

0

我认为你的左帽宽度是错误的?如果你的第一张图片只有 13 像素宽,那么左边的上限怎么可能是 16?

左帽是原始图像上保持未拉伸的宽度

于 2012-06-13T15:19:12.317 回答
0

为了跟进保罗的回答,

您要确保留出一些空间进行拉伸,因此请使用 Photoshop 或类似工具放大并确定绝对需要哪些剩余像素。

看到这个:http: //idevrecipes.com/2010/12/08/stretchable-images-and-buttons/

于 2012-06-13T15:48:15.823 回答
0

LeftCapWidth 应为 6.5;

UIImage *shareImage = [[UIImage imageNamed:@"btn_red"] stretchableImageWithLeftCapWidth:6.5 topCapHeight:0.0];
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46.0f, 30.0f)];
于 2012-06-13T17:18:35.360 回答