[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.