Three ways to stretch IOS uiimage

Source: Internet
Author: User

The first of these methods

//-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (Nsinteger) Topcapheight __tvos_prohibited;

//leftcapwidth: left not stretched area

//topcapheight: does not stretch the area above


UIImage *image =[UIImageimagenamed:@ " Chatdetail_info_other "];

uiimageview *imageview=[[ uiimageview alloc ] initwithframe : CGRectMake ( 20 60 size width size height

ImageView. Image =image;

[self. View addsubview: ImageView];

    uiimage *image1 =[ uiimage imagenamed : @ "Chatdetail_info_other" ];

    image1=[image1 Stretchableimagewithleftcapwidth :image1. size width * 0.3 topcapheight :image1. size height * 0.7 ];

uiimageview *imageview1=[[uiimageviewalloc ] initWithFrame:cgrectmake , $ , Max )];

ImageView1. Image =image1;

[self. View addsubview: imageView1];


The second method of

//-(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets Ns_available_ios (5_0);



There is a concept called end caps in iOS that specifies which part of the picture does not have to be stretched. For example , the black represents the rectangular area that needs to be stretched, and the edges that do not need to be stretched up or down are called end caps.



This method only receive a parameter of type uiedgeinsets, you can specify the left cover width, right end cover width, top cover height, bottom cover height by setting uiedgeinsets left, starboard, top, bottom respectively .

[Image1resizableimagewithcapinsets:Uiedgeinsetsmake(Image1.size.Height*0.9, Image1.size.width*0.9, Image1.size.Height*0.9, Image1.size.width*0.9)];



The third method of

//-(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets Resizingmode: (uiimageresizingmode ) Resizingmode Ns_available_ios (6_0);


// compare methods in iOS5.0, only one uiimageresizingmode parameter is used to specify the pattern of the extrusion:

//Uiimageresizingmodestretch: Stretch mode to fill a picture by stretching the rectangular area specified by the Uiedgeinsets

///Uiimageresizingmodetile: Tile mode, fills the picture by repeating the uiedgeinsets specified rectangular area

[Image1resizableimagewithcapinsets:Uiedgeinsetsmake(Image1.size.Height*0.9, Image1.size.width*0.9, Image1.size.Height*0.9, Image1.size.width*0.9)Resizingmode:Uiimageresizingmodestretch];


This code effect is the same as the second

Three ways to stretch IOS uiimage

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.