Several ways to stretch pictures

Source: Internet
Author: User

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

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.