Several ways to stretch pictures in iOS
Last Update:2015-10-08
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>