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