You use a function, use - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeightinstead - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets.
Install the top, left cover, to stretch the image as described in the following code.
Objective-c
UIImage *image = [UIImage imageNamed:@"test"];
CGFloat capTop = 50;
CGFloat capLeft = 5;
UIImage *capImage = [image stretchableImageWithLeftCapWidth:capLeft topCapHeight:capTop];
Swift
let image = UIImage(named: "stretchableImage")
let capTop:Int = 50;
let capLeft:Int = 5;
let capImage = image?.stretchableImage(withLeftCapWidth: capLeft, topCapHeight: capTop)
Alternet solution
The same result can be achieved using the following function.
Objective-c
UIImage *stretchedImage = [image resizableImageWithCapInsets:
UIEdgeInsetsMake(50, 50, 0, 50)];
Swift
var stretchedImage = image?.resizableImage(withCapInsets: UIEdgeInsets(top: 50, left: 50, bottom: 0, right: 50), resizingMode: .stretch)
. , (ImageView, Button ..). .