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?

Answers


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.

Source


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?

Matt


You can use the resizableImageWithCapInsets method of UIImage

Example-->

Original Image

Output Image

UIImage *im = [[UIImage imageNamed:@"a.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 13)];

Need Your Help

Meaning of a Threaded Program Specification

java c++ multithreading stream

I am supposed to implement a multithreaded application, but I have never one done before. I've found some good tutorials and am beginning to get the jist of multithreading. However, I've been given...

PL/SQL issues returning a sequence scalar value

c# oracle stored-procedures plsql

I'm trying to return sequence.nextval to my program from a proc stored in a package. I'm pretty green when it comes to PL/SQL and I'm kind of at a loss as to what is happening. The error that is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.