iOS picture clipping

Source: Internet
Author: User

/*

-(ID) Initwithcoder: (Nscoder *) Adecoder

{

if (self = [Super Initwithcoder:adecoder]) {

set the main layer fillet of a picture

Self.iconView.layer.cornerRadius = 8;

set partial clipping beyond the main layer

Self.iconView.clipsToBounds = YES;

Self.iconView.layer.masksToBounds = YES;

NSLog (@ "Initwithcoder");

}

return self;

}

*/

-(void) awakefromnib

{

// set the main layer fillet of the picture

self. IconView. Layer. Cornerradius = 8;

// Set partial clipping beyond the main layer

self. IconView. Clipstobounds = YES;

}

#import "Uiimage+dy.h" @implementation UIImage (DY) + (Instancetype) Circleimagewithname: (NSString *) name BorderWidth: (        CGFloat) borderWidth bordercolor: (Uicolor *) bordercolor{//1. Loading the original image UIImage *oldimage = [UIImage imagenamed:name];    2. Open context CGFloat Imagew = oldImage.size.width + 2 * borderWidth;    CGFloat Imageh = oldImage.size.height + 2 * borderWidth;    Cgsize imageSize = Cgsizemake (Imagew, Imageh);        Uigraphicsbeginimagecontextwithoptions (ImageSize, NO, 0.0);        3. Get the current context cgcontextref CTX = Uigraphicsgetcurrentcontext ();    4. Draw the frame (great circle) [BorderColor set]; CGFloat Bigradius = Imagew * 0.5; Circle radius cgfloat CenterX = Bigradius;    Center CGFloat centery = Bigradius;    Cgcontextaddarc (CTX, CenterX, CenterY, Bigradius, 0, M_PI * 2, 0); Cgcontextfillpath (CTX);    Draw Circle//5. Small round cgfloat Smallradius = bigradius-borderwidth;    Cgcontextaddarc (CTX, CenterX, CenterY, Smallradius, 0, M_PI * 2, 0); Cropping (the things that are drawn later are affected by clipping) Cgcontextclip (CTx);        6. Drawing [Oldimage Drawinrect:cgrectmake (BorderWidth, BorderWidth, OldImage.size.width, OldImage.size.height)];        7. Take figure UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext ();        8. End context Uigraphicsendimagecontext (); return newimage;}

iOS picture clipping

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.