2012-04-04 46 views
0

环境: Xcode4.3.1,SDK5.1IOS映像不能被拉伸

我想舒展只图像的一部分,所以我用写这样的代码:

leftImage = [UIImage imageNamed:@"leftStyleBackground.png"]; 
UIEdgeInsets insets = UIEdgeInsetsMake(2, 14, 2, 2); 
if ([leftImage respondsToSelector:@selector(resizableImageWithCapInsets:)]) 
    leftImage = [leftImage resizableImageWithCapInsets:insets]; 
else { 
    leftImage = [leftImage stretchableImageWithLeftCapWidth:14 topCapHeight:2]; 
} 

然而,结果是原始图像只能重复出现以填充视图框。

如果我使用 - stretchableImageWithLeftCapWidth:topCapHeight:方法可以正确拉伸图像。

是什么想法,为什么在ios5中的新方法无法正常工作?

+0

有没有找到一个解决方案呢?我看到同样的事情。 – jimmyg 2012-09-07 00:48:14

回答

1

resizableImageWithCapInsets:拼接图像区域。

如果需要拉伸:

6.0及以上 - 用途:resizableImageWithCapInsets:resizingMode:与resizingMode设置为UIImageResizingModeStretch

6.0之前 - 使用:stretchableImageWithLeftCapWidth:topCapHeight: