0

Does anyone know how to do this without using [UIImage resizableImageWithCapInsets:]? I'm trying to provide compatibility for users that cannot run iOS5.

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

Please note that I'm not looking to create a 1px stretchable image, I want to tile the area that is defined between the insets when the UIImage is resized. That is, [UIImage stretchableImageWithLeftCapWidth: topCapHeight:] does not do the trick.

Many Thanks!

DTs
  • 1,196
  • 1
  • 11
  • 28

1 Answers1

0

You can't do this pre iOS 5 in the way you want unfortunately. The only option is [UIImage stretchableImageWithLeftCapWidth: topCapHeight:]. With it you have to specify a single pixel which gets tiled horizontally and vertically. Unfortunately there's no way to do what you want directly with UIImage pre iOS 5.

UPDATED: I've updated this answer because DTs was totally correct.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
  • These 2 methods actually do very different things: the former will tile the area defined within the insets. That way you can have a pattern repeating. The latter will only repeat a single pixel or rows, in your example pixel 6,11. In effect, the image is stretched when resized, not tiled. It only works for images that have uniform colors, not patterns. – DTs Nov 29 '11 at 09:16
  • I posted a screenshot to explain better what the difference is: http://imageshack.us/photo/my-images/52/tilevsstretch.jpg/ – DTs Nov 29 '11 at 09:38
  • Very good point DTs - I've updated accordingly. Not quite sure what I was thinking when I wrote that answer, apologies. – mattjgalloway Nov 29 '11 at 11:58