Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for UIView's contentStretch?

In iOS 6.0 the contentStretch property of UIView was deprecated. How can I achieve the same functionality with new/old/other API?

The functionality I am looking for is stretching just part of an image (everything but the edges) on a UIButton.

like image 606
EladWeinson Avatar asked Mar 27 '13 16:03

EladWeinson


1 Answers

Use resizableImageWithCapInsets and UIEdgeInsets to make a stretching UIButton background image. For example:

UIImage* image = [UIImage imageNamed:@"image.png"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];
[button setBackgroundImage:image forState:UIControlStateHighlighted];

I don't think you can stretch more than one pixel both horizontal and vertical.

Hope this helps.

like image 104
Matti Jokipii Avatar answered Sep 29 '22 23:09

Matti Jokipii