Iphone image stretching Methods

Source: Internet
Author: User

After ios6, the image stretching method has been extended to three functions:

1. Methods provided by ios4:

-(UIImage *) stretchableImageWithLeftCapWidth :( NSInteger) leftCapWidth topCapHeight :( NSInteger) topCapHeight

This function is an instance function of UIImage. Its function is to create an image whose content can be stretched but its corners are not stretched. Two parameters are required, the first parameter is the width of the left border without stretching the area, and the second parameter is the width of the top border without stretching the area. In essence, the operation is to copy and stretch a pixel, therefore, there is no gradient effect, which is also a disadvantage.

The meaning of the parameter is that if the parameter is set to 10, 5. Then, there are 10 points on the left and 5 points on the top of the image. It will not be stretched. vertices with the x coordinate of 11 will be horizontally copied, and vertices with the y coordinate of 6 will be vertically copied. Note: Only copy a vertex pixel to the specified width.

2. Methods provided by ios5

-(UIImage *) resizableImageCapInsets :( UIEdgeInsets) Insets

The Insets parameter is in the format of (top, left, bottom, right). A line is drawn from the top, left, bottom, and right, in this way, a rectangular area is specified for an image. Only the part in the box is stretched, while the part outside the box remains changed. For example (20, 5, 10, 5), it means that the part in the rectangle can be stretched, while the rest remains unchanged.

3. Methods provided by ios6:

-(UIImage *) resizableImageWithCapInsets :( UIEdgeInsets) capInsets resizingMode :( UIImageResizingMode) resizingMode

The Insets parameter is the same as ios5. The difference is that a stretching mode is added later. ios6.0 provides

UIImageResizingModeTile and UIImageResizingModeStretch are two modes, namely tile mode and stretch mode. Tile is to copy the rectangular area block specified by your Insets to fill the area of your specified image, and stretch is to stretch the rectangular area block specified by your Insets to fill the area of your desired image. I think you can see the progress of 4.0. Compared with the previous one, the resize of an image is changed from a vertex to a rectangle, in this way, the gradient effect of the specified block can also be displayed.

However, if you need a machine compatible with 4.0, you still need to use the old function to resize the image.

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.