如何在iOS5之前执行[UIImage resizableImageWithCapInsets:]?

时间:2011-12-01 01:07:49

标签: ios ios5 uiimage

以下代码在指定的insets中平铺图像区域:

UIEdgeInsets imgInsets = UIEdgeInsetsMake(10.f, 5.f, 13.f, 44.f);
UIImage *image = [[UIImage imageNamed:@"fileName"] resizableImageWithCapInsets:imgInsets]; 

但是这只适用于iOS5。如何在兼容iOS5之前获得相同的结果?

据我所知,

[UIImage stretchableImageWithLeftCapWidth: topCapHeight:]是不合适的,因为它假设可平铺区域的宽度为1px。换句话说,它不会平铺,它会拉伸。因此,它不适用于图案,仅适用于单色图像。这将在下面的屏幕截图中进行演示。

然后有[UIColor colorWithPatternImage:],但这假设整个图像需要平铺,它不允许必须保持上限的插图。

感谢任何帮助,谢谢。

enter image description here

1 个答案:

答案 0 :(得分:2)

我一直在寻找解决方案。此时我想我会在原始UIImage上使用respondsToSelector:@selector(resizableImageWithCapInsets:)来查看该方法是否可用。如果没有,则使用可伸缩的图像。

我仍在寻找更好的解决方案,如果有人提出,我会更新答案。