Dmitry Dmitry - 3 months ago 20
iOS Question

How to use resizableImageWithCapInsets on UIImage?

I want to take a picture like this:

enter image description here

And I wrote the code:

[[[UIImage imageNamed:@"background.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(1.f, 1.f, 1.f, 1.f)]
drawInRect:rect];


But with this code I took that:

enter image description here

Why??? How to draw a resized image in rect with fixed 1px on all sides?

Answer

Use the following code to stretch the image on iOS 6+:

[[[UIImage imageNamed:@"background.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1.f, 1.f, 1.f, 1.f) resizingMode:UIImageResizingModeStretch]drawInRect:rect];
Comments