Using the Stretchableimagewithleftcapwidth method to implement a scalable picture

Source: Internet
Author: User

-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (Nsinteger) topcapheight

This is an example method of UIImage, its function is to create a content can be stretched, and the corner does not stretch the picture, requires two parameters, the first is the width of the left not stretched area, the second parameter is not stretched above the height.

Depending on the width and height of the setting, the next pixel is extended left and right and stretched up and down.

Note: The stretchable range is 1 vertical pixels after leftcapwidth, and 1 horizontal pixels after the distance of Topcapheight.

The meaning of the parameter is: if the parameters are 10 and 5 o'clock, 10 pixels to the left of the picture, 5 pixels above the top, not stretched, and a pixel with an X coordinate of 11 is tiled horizontally, and a pixel with a Y coordinate of 6 is tiled vertically.

Note: Only one pixel is tiled to a certain width, and the remaining pixels behind the image are not stretched.

1 UIImage *img=[uiimage imagenamed:@ "bubbleself.png"]; 2 img=[img stretchableimagewithleftcapwidth: topcapheight:[]; 3 uiimageview *imgv=[[Uiimageview alloc]initwithimage:img]; 4 [IMGV setframe:cgrectmake (ten)]; 5 [self. View ADDSUBVIEW:IMGV];

The effect is as follows (the effect produced by using the Stretchableimagewithleftcapwidth method on the left side is the original):

Using the Stretchableimagewithleftcapwidth method to implement a scalable picture

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.