Several ways to stretch pictures in iOS

Source: Internet
Author: User
<span id="Label3"></p><p><p>1. Uiimageview Overall stretching</p></p><p><p>Uiimageview-contentmode</p></p><pre class="brush:cpp;toolbar: true; auto-links: false;">Typedef ns_enum (nsinteger, uiviewcontentmode)  {     uiviewcontentmodescaletofill,         //  default   extrude (deform)     UIViewContentModeScaleAspectFit,      //  equal scale stretching     UIViewContentModeScaleAspectFill,     //  Proportional fill      UIViewContentModeRedraw,               // redraw on bounds change  (this is Unclear)       uiviewcontentmodecenter,              //   Below is no stretch by position show     UIViewContentModeTop,     uiviewcontentmodebottom,    uiviewcontentmodeleft,     uiviewcontentmoderight,    uiviewcontentmodetopleft,    uiviewcontentmodetopright,    uiviewcontentmodebottomleft,     uiviewcontentmodebottomright,};</pre><p><p>Demo:https://github.com/vitoziv/vicmaimageview</p></p><p><p>2. UIImage Partial stretching</p></p><pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">Displays the non-stretched area by 4-side spacing-(UIImage *) resizableimagewithcapinsets: (uiedgeinsets) capinsets ns_available_ios (5_0); Stretch by 2 points-(UIImage *) stretchableimagewithleftcapwidth: (nsinteger) leftcapwidth topcapheight: (nsinteger) topcapheight ;</pre></pre><pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">-(UIImage *) resizableimagewithcapinsets: (uiedgeinsets) capinsets resizingmode: (uiimageresizingmode) resizingMode;/ /stretch mode typedef ns_enum (nsinteger, uiimageresizingmode) {uiimageresizingmodetile,//for Zone copy mode stretching uiimageresizingmodestre Tch,//the Gradient Copy Mode stretch};</pre></pre><p><p>3.UIImage Modify Size</p></p><pre class="brush:cpp;toolbar: true; auto-links: false;">Inside scaling, one becomes equal to the longest edge, the other is less than or equal to the longest edge-  (uiimage *) scaletosize: (cgsize) newsize {     cgfloat width = self.size.width;    cgfloat height=  self.size.height;    cgfloat newsizewidth = newsize.width;     CGFloat newSizeHeight= newSize.height;    if  (width <=  newSizeWidth &&        height <=  Newsizeheight)  {        return self;     }        if  (width == 0 | |  height == 0 | |  newsizeheight == 0 | |  newsizewidth == 0)  {        return nil;     }    CGSize size;    if  (Width / height > newsizewidth / newsizeheight)  {         size = cgsizemake (newsizewidth, newsizewidth * height /  width);     } else {        size  = cgsizemake (newsizeheight * width / height, newsizeheight);     }    return [self drawimagewithsize:size];} -  (uiimage *) drawimagewithsize:  (cgsize) size {    cgsize drawsize  = cgsizemake (floor (size.width),  floor (size.height));     Uigraphicsbeginimagecontext (drawsize);         [self drawinrect: CGRectMake (0, 0, drawsize.width, drawsize.height)];    uiimage * Newimage = uigraphicsgetimagefromcurrentimagecontext (); &NBsp;   uigraphicsendimagecontext ();     return newimage;} </pre><p><p><br></p></p><p><p>Several ways to stretch pictures in iOS</p></p></span>

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.