Three ways to set the rounded corners of a picture

Source: Internet
Author: User

    //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

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.