Problem: When the picture is small, and the picture frame. or the button, larger than the picture, fills the entire button to deform, stretching the picture so that it does not deform even though it is stretched.
After the extrusion process:
Way 1. Through the Resizableimagewithcapinsets:resizingmode method.
// The interior is resized according to the Resizingmode
Implementation code:
UIImage *img = [UIImage imagenamed:@ "redbutton"]; 0.5 ; 0.5 ; *newimg = [img resizableimagewithcapinsets:uiedgeinsetsmake (H,l, H, l) Resizingmode:uiimageresizingmodestretch] ; = Newimg;
Parameter description:
(uiedgeinsets) Capinsets: The part that does not stretch, sets the distance that does not stretch up or down, only stretches the middle one small block or a point.
(Uiimageresizingmode) Resizingmode: This is an enumeration value that represents how the picture is stretched.
Two types of styles:
uiimageresizingmodetile,//fills the interior area of the new picture by repeating a small area of the interior//the image is tiled the it is resized. In other words, the interior region of the original image would be repeated to fill in the interior region of the newly res ized image. uiimageresizingmodestretch,//fills the inner area of the new picture by scaling the inner region of the interior of the picture//the image is stretched when it is resized. In other words, the interior region of the original image would be scaled to fill in the interior region of the newly resiz Ed imaged.
Mode 2: Through the storyboard, modify, X,y,width,height value. A point is determined by XY, and the width is determined by width,heigth, thereby obtaining a small piece of content in the picture, thus stretching the small piece of content
This is a property of UIView
@property (nonatomic) cgrect contentstretch ns_deprecated_ios (3_0,6_0) __tvos_prohibited;//animatable. Default is unit rectangle {{0,0} {.}}. Now deprecated:please use-[uiimage resizableimagewithcapinsets:] To achieve the same effect.
This attribute has expired and the official recommended way to use one.
#方式3: By method Stretchableimagewithleftcapwidth:topcapheight. This is a way of uiimage.
-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (nsinteger) Topcapheight __TVOS_ prohibited;
Method Description:
@interface UIImage (uiimagedeprecated)// disapprove of Use//Use resizableimagewithcapinsets:and capinsets.-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (nsinteger) Topcapheight __TVOS_ Prohibited, @property (nonatomic,ReadOnly) Nsinteger Leftcapwidth __tvos_prohibited;//default is 0. If Non-zero, Horiz. stretchable. Right caps is calculated as Width-leftcapwidth-1If the leftcapwidth is not 0, it can be stretched horizontally and the right cover part range is equal to (width-leftcapwidth-1)
@property (Nonatomic,ReadOnly) Nsinteger Topcapheight __tvos_prohibited;//default is 0. If Non-zero, vert. stretchable. Bottom caps is calculated as Height-topcapwidth-1If Topcapheight is not 0, it can be stretched up and down, and the bottom coverage portion is equal to (height-topcapwidth-1) @end
#实现代码
UIImage *img = [UIImage imagenamed:@ "redbutton"]; 0.5 ; 0.5 ; *newimg = [img stretchableimagewithleftcapwidth:h topcapheight:l]; = Newimg;
#方式4;
Summarize:
Say is four ways, plainly or a way to stretch the picture in its own way. Generally, stretching the entire picture results in corner deformation, which is defined by stretching the area for stretching and the corners are not deformed.
Several ways to stretch a picture