[Original] image stretching processing for iOS Learning (like qq bubbles) and ios stretching

Source: Internet
Author: User

[Original] image stretching processing for iOS Learning (like qq bubbles) and ios stretching

The principle is to stretch the content and protect the edges.

Method 1:

① [Image resizableImageWithCapInsets: UIEdgeInsetsMake (30, 30, 30)]; ② [image resizableImageWithCapInsets: UIEdgeInsetsMake (30, 30, 30, 30) resizingMode: latest]; typedef NS_ENUM (NSInteger, UIImageResizingMode) {UIImageResizingModeTile, (tile) UIImageResizingModeStretch, (stretch )};

The above method is to stretch the unprotected part of the image.

① Directly pass in the protection range without setting the image stretching mode. The default value is UIImageResizingModeTile (tile type), which means to display the image in a tiled manner in the original size.

② Set the image stretch mode

 

Method 2:

[image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];

The original method of Apple has been discarded. This method will only stretch the area 1*1 in the middle.

Generally, the input value is half the image size.

Calculation formula:

// Left (input)

// Top (input)

// Width
// Height
// Right = width-left-1; (calculated)
// 1 = width-left-right;

// Bottom = height-top-1; (calculation)

// 1 = height-top-bottom;

 

Method 3:

No need to write code

Drag the image to images. xcassets. The specific setting steps are as follows:

After setting the image according to the method, the image can be stretched all the time.

Related Article

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.