Dmitry
Dmitry

Reputation: 14622

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?

Upvotes: 1

Views: 1280

Answers (1)

Dmitry
Dmitry

Reputation: 14622

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];

Upvotes: 2

Related Questions