//There are three ways to understand the fillet, and one way to look at it//the first way to fillet: (set layer property)Uiimageview *imageview =[[Uiimageview alloc]init]; Imageview.backgroundcolor=[Uicolor Purplecolor]; Imageview.frame= CGRectMake ( the, -, $, $); Imageview.image= [UIImage imagenamed:@"1"]; //cut out the extra partsImageView.layer.masksToBounds =YES; //Set rounded cornersImageView.layer.cornerRadius = imageView.frame.size.width/2; [Self.view Addsubview:imageview];
//the second way to fillet: (use Bezier: Uibezierpath and the core Graphics frame to draw a fillet)Uiimageview *imageview =[[Uiimageview alloc]init]; Imageview.backgroundcolor=[Uicolor Purplecolor]; Imageview.frame= CGRectMake ( the, -, $, $); Imageview.image= [UIImage imagenamed:@"1"]; /** * to draw pictures * * @param size#> picture size description#> * @param opaque#> is transparent Description#> ; * @param scale#> Size description#> * * @return Nil*/uigraphicsbeginimagecontextwithoptions (imageView.bounds.size, NO,1.0); /** * Draw a circle chart using Bezier curve * * @param cgrect Picture Path * * @return fillet size*/[[Uibezierpath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addclip]; [ImageView DrawRect:imageView.bounds]; Imageview.image=Uigraphicsgetimagefromcurrentimagecontext (); //Finish DrawingUigraphicsendimagecontext (); [Self.view Addsubview:imageview];
//the third Way to fillet: (use Cashapelayer and Uibezierpath) to set the fillet Note: This method consumes less memory and renders faster.//First Import frames #import <AVFoundation/AVFoundation.h>Uiimageview *imageview =[[Uiimageview alloc]init]; Imageview.backgroundcolor=[Uicolor Purplecolor]; Imageview.frame= CGRectMake ( the, -, $, $); Imageview.image= [UIImage imagenamed:@"1"]; Uibezierpath*path =[Uibezierpath bezierPathWithRoundedRect:imageView.bounds byroundingcorners:uirectcornerallcorners cornerradii : ImageView.bounds.size]; Cashapelayer*masklayer =[[Cashapelayer alloc]init]; //Set SizeMasklayer.frame =Imageview.bounds; //Set graphic appearanceMasklayer.path =path. Cgpath; ImageView.layer.mask=Masklayer; [Self.view Addsubview:imageview];
Three ways to set the rounded corners of a picture