IOS UIimage stretching Methods

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.