iOS development-uiimageview efficiently set up radius

Source: Internet
Author: User

rounded settings are ubiquitous in iOS and are easy to develop, but sometimes if a page has a large number of images that need to be rounded, it is easy to create performance problems, Uiimageview ios9.0 before setting the fillet will produce off-screen rendering,after 9.0 will not produce off-screen rendering

So you need to add some changes to the way you want to set round corners on a daily basis:

1. The simplest picture fillet setting:

    Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake (100,200, N.)];    [Self.imageview setimage:[uiimage imagenamed:@ "flyelephant.jpg"];    self.imageview.layer.cornerradius=50;    Self.imageview.layer.maskstobounds=yes;    [Self.view AddSubview:self.imageView];

2. Set rasterize raster processing, will put the picture in the buffer, do not continue to do picture rendering:

    Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake (100,200, N.)];    [Self.imageview setimage:[uiimage imagenamed:@ "dress3.jpg"];    self.imageview.layer.cornerradius=50;    Self.imageView.layer.shouldRasterize = YES;    Self.imageview.clipstobounds=yes;    Self.imageview.layer.rasterizationscale=[uiscreen Mainscreen].scale;  Do not set will blur, do not believe you can try    [Self.view AddSubview:self.imageView];

3.UIBezierPath Bézier curve drawing (recommended)

    Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake (100,200, N.)];    UIImage *anotherimage = [UIImage imagenamed:@ "flyelephant.jpg"];    Note The third option is set    uigraphicsbeginimagecontextwithoptions (Self.imageView.bounds.size, NO, [UIScreen mainscreen]. scale);    Crop a circle before drawing    [[Uibezierpath bezierPathWithRoundedRect:self.imageView.bounds                                cornerradius:50] Addclip] ;    The picture is drawn inside the set circle    [Anotherimage drawInRect:self.imageView.bounds];    Get picture    self.imageView.image = Uigraphicsgetimagefromcurrentimagecontext ();    Finish Drawing    uigraphicsendimagecontext ();    [Self.view AddSubview:self.imageView];

Reference: Http://stackoverflow.com/questions/11049016/cliptobounds-and-maskstobounds-performance-issue

Http://stackoverflow.com/questions/17593524/using-cornerradius-on-a-uiimageview-in-a-uitableviewcell

iOS development-uiimageview efficiently set up radius

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.