iOS picture stretching

Source: Internet
Author: User

Commonly used picture stretch scenes are: Chat page bubbles, you need to stretch according to content, but the fillet stretch will deform, in order to avoid fillet stretching, you can specify the stretch area. The UIImage entity calls the following method to specify the extruded area.

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

Leftcapwidth indicates the width of the hat on the left (horizontal direction), Rightcapwidth = Image.size.width-(image.leftcapwidth + 1);

Topcapheight indicates the hat width at the top (vertical direction), Bottomcapheight = Image.size.height-(image.topcapheight + 1);

According to the Apple documentation, the stretch area is the 1*1 pixel that removes the hat area.

For example, use a 40*40pt bubble as the background of the chat content, set its leftcapwidth to 5pt,topcapheight to a PT, such as: When the picture is stretched, only the red circle area is stretched , the area of the hat outside The red circle is protected and does not deform .

1 [[UIImage imagenamed:@ "chat_sender_green_bg"] Stretchableimagewithleftcapwidth:5 topcapheight:+];

The effect is as follows:

iOS picture stretching

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.