How can I stretch (not tile) an UIImage with end caps
I have a few images in interface that have a border and some background inside. Kind of like this:
I want to stretch them, leaving the border intact. The resizableImageWithCapInsets method seems like it should work, but it tiles the interior part of the image. Which is not what I want. Can I somehow make it stretch the interior part of image?
Use the method:
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
and pass for resisizingMode UIImageResizingModeStretch
I believe they stated in one of the WWDC 2012 sessions that if the interior area is 1 pixel wide or high the system assumes it should be stretched, otherwise the system assumes it should be tiled. However using this slightly different API you have the option of specifying whether you want stretch or tile.
This should work, maybe you're setting the values for the insets wrong?
If you set the values wrong then you may see what appears to be tiling of the section left in the centre: https://developer.apple.com/library/ios/documentation/uikit/reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImage/resizableImageWithCapInsets:
Bear in mind that the value for each inset must be at least 1 as well.
Any chance we could see how you define the image with offset?
You can use the resizableImageWithCapInsets method of UIImage
Example--> Original Image
UIImage *im = [[UIImage imageNamed:@"a.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 13)];