IOS UIimage stretching Methods
Method 1
//-(UIImage *) stretchableImageWithLeftCapWidth :( NSInteger) leftCapWidth topCapHeight :( NSInteger) topCapHeight _ TVOS_PROHIBITED; // leftCapWidth: no stretch area on the left // topCapHeight: UIImage * image = [UIImageimageNamed: @ "chatdetail_info_other"]; UIImageView * imageView = [[UIImageViewalloc] initWithFrame: CGRectMake (20, 60, image. size. width, image. size. height)]; imageView. image = image; [self. viewaddSubview: imageView]; UIImage * image1 = [UIImageimageNamed: @ "chatdetail_info_other"]; image1 = [image1 stretchableImageWithLeftCapWidth: image1.size. width * 0.3 topCapHeight: image1.size. height * 0.7]; UIImageView * imageView1 = [[UIImageViewalloc] initWithFrame: CGRectMake (20,220,200,150)]; imageView1.image = image1; [self. viewaddSubview: imageView1];
Method 2
//-(UIImage *) resizableImageWithCapInsets :( UIEdgeInsets) capInsets NS_AVAILABLE_IOS (5_0 );
There is an end cap in iOS that specifies which part of the image does not need to be stretched. For example, black indicates the area of the rectangle to be stretched. The top, bottom, left, and right edges that do not need to be stretched are called end caps.
This method only receives one UIEdgeInsets parameter. You can set left, right, top, and bottom of UIEdgeInsets to specify the width, width, height, and height of the End Cover.
[Image1 resizableImageWithCapInsets: UIEdgeInsetsMake (image1.size. height * 0.9, image1.size. width * 0.9, image1.size. height * 0.9, image1.size. width * 0.9)];
Method 3
//-(UIImage *) resizableImageWithCapInsets :( UIEdgeInsets) capInsets resizingMode :( UIImageResizingMode) resizingMode NS_AVAILABLE_IOS (6_0 );
// Compare the method in iOS5.0 with only one UIImageResizingMode parameter to specify the stretch mode:
// UIImageResizingModeStretch: stretch mode. Fill the image by stretching the area of the rectangle specified by UIEdgeInsets.
// UIImageResizingModeTile: tiled mode. The image is filled by repeatedly displaying the rectangular area specified by UIEdgeInsets.
[Image1 resizableImageWithCapInsets: UIEdgeInsetsMake (image1.size. height * 0.9, image1.size. width * 0.9, image1.size. height * 0.9, image1.size. width * 0.9) resizingMode: resize];
This code works the same way as the second one.