Three ways to stretch iOS pictures

Source: Internet
Author: User

Method One:

There is a concept called end caps in iOS that specifies which part of the picture does not have to be stretched, and the edges that do not need to be stretched up or down are referred to as end caps.

1 //Use resizableimagewithcapinsets:and capinsets. 3-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (nsinteger) Topcapheight __TVOS_ prohibited;4@property (Nonatomic,ReadOnly) Nsinteger Leftcapwidth __tvos_prohibited;//default is 0. If Non-zero, Horiz. stretchable. Right caps is calculated as Width-leftcapwidth-15@property (Nonatomic,ReadOnly) Nsinteger Topcapheight __tvos_prohibited;//default is 0. If Non-zero, vert. stretchable. Bottom caps is calculated as Height-topcapwidth-1

1  // Stretch area distance left end width   2  0.5f ;   3  // stretch area distance to top  height 4  0.5f ;   5  // assign a value  to image again 6  

Method Two:

By setting the left, right, top, bottom of the uiedgeinsets, you can specify the width of the picture stretch area, the width of the end, the top height, the bottom height
// by setting the left, right, top, bottom of the uiedgeinsets, you can specify the width of the picture stretch area, the width of the end, the top height, the bottom height // Create a resizable version of this image. The interior was tiled when drawn.

 cgfloat top = 10 ;   10   ; //   stretch area distance from bottom height  cgfloat left = 20 ;  //   stretch area distance left end width  Cgfloat right = 20 ;  //    stretch area distance to the right-hand width  uiedgeinsets insets =  uiedgeinsetsmake (top, left, bottom, right);  //   extrude re-assigns image to  image = [image  Resizableimagewithcapinsets:insets]; 

Method Three:

In iOS6.0, UIImage also provides a way to process picture stretching, Comparing the methods in iOS5.0, a uiimageresizingmode parameter is used to specify the pattern of the extrusion: Uiimageresizingmodestretch: extrude mode, which fills the picture by stretching uiedgeinsets the specified rectangular area Uiimageresiz Ingmodetile: Tile mode, fills the picture by repeating the uiedgeinsets specified rectangular area
/*
* In iOS6.0, UIImage also provides a way to handle picture stretching, comparing the methods in iOS5.0, with a uiimageresizingmode parameter that specifies the pattern of stretching: * Uiimageresizingmodestretch: Stretch mode, fills the picture by stretching the rectangular area specified by Uiedgeinsets * Uiimageresizingmodetile: Tiled mode, Fills the picture by repeating the rectangular area specified uiedgeinsets *// The interior is resized according to the Resizingmode

CGFloat top =Ten;//stretch area distance to top heightCGFloat bottom =Ten;//stretch area distance from bottom heightCGFloat left = -;//Stretch area distance left end widthCGFloat right = -;//stretch area distance to right-hand widthUiedgeinsets insets =Uiedgeinsetsmake (top, left, bottom, right);//to assign a value to an image after stretchingimage = [Image resizableimagewithcapinsets:insets Resizingmode:uiimageresizingmodestretch];

Three ways to stretch iOS pictures

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.