Several ways to stretch pictures

Source: Internet
Author: User

Objective

  -Although the picture is stretched before, there are several ways to stretch the picture in iOS. There was no time to tidy up, today I am ready to put together some of the methods I know at present, focusing on non-code methods.

Method

1. Before IOS5

This method, you just fill the left and the top of the length, and then the right and the length of the following will be the total length minus one, the method will automatically use the middle of the point to stretch.

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

Example:

UIImage *image = _loginbtn.currentbackgroundimage;         stretchableimagewithleftcapwidth:0.5 * image.size.width topcapheight:0.5 *  image.size.height];        [_loginbtn setbackgroundimage:image forstate:uicontrolstatenormal];

  

2. Method Two: appear in IOS5

This method uses the following parameter to specify the safe distance between the upper and lower sides, that is, the middle part stretches

-(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets

3. Method Three: appearing in IOS6

This method is almost the same as the method in IOS5.0, but it has an optional mode.

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

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

-(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets Resizingmode: (uiimageresizingmode) ResizingMode

4. Method Four: Images.xcassets

After xcode5.0, in the images.xcassets can do some of the material to do some processing, you can see after clicking on the footage, in the attribute column has a slicing.

-click Slicing to choose between horizontal and vertical stretching, or at the same time.

-The following center has two options tiles and stretches

-Tiles: Tiled

-Stretches: Stretching

( Note : Xcode6 selection mode after the parameters of the default is good, before the XCODE5 also drag the inside of the line)

5. Method Five: Xib and Storyborad inside the property can be set

-Can see you click on the Fourth button above properties, the bottom can see stretching this property, x and y select 0.5 for half of the width or length, below 0 and 0 for the middle of a point stretch

Note : This method can only be used on the image, not on the button, button can use the above several methods.

  

Several ways to stretch 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.