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