Three ways to achieve fillet effect with ios_ view and comparison

Source: Internet
Author: User

With code, there are at least three ways to add a fillet effect to a view. Attached examples:
Https://github.com/weipin/RoundedCorner

method One, Layer.cornerradius

The first method is the simplest, using the Cornerradius property of the Layer object to achieve the fillet effect, the code is as follows:

View.layer.cornerRadius = 8.0;
View.layer.masksToBounds = YES;

The disadvantage is that there will be 2 times rending passes. First off-screen draw a picture with rounded corners and then draw a second time on the view.

method Two, set the drawing area with rounded angle by Uibezierpath object

The benefit of this approach is that there is only one rending pass, which is the most efficient of the three methods. The disadvantage is that the override view is required. The code is as follows:

-(void) DrawRect: (cgrect) Rect {
CGRect bounds = self.bounds;

[[Uicolor Whitecolor] set];
Uirectfill (bounds);

[[Uibezierpath Bezierpathwithroundedrect:rect cornerradius:8.0] addclip];

[Self.image Drawinrect:bounds];
}

Method Three, create a new diagram from another mask diagram


First, a mask is needed, and the mask and the original are synthesized to get a new picture with rounded corners. The efficiency and method of a similar, synthetic new diagram is equivalent to the off-screen. The advantage of this method is that it can be controlled not only by the fillet, but also by the mask graph.

Summarize:

If you want efficiency (for example, to increase the number of scrolling frames for a table view), use method two more. To be convenient, nature is the method one. If the desired special shape Uibezierpath object cannot be formed, consider method three.

Example: Https://github.com/weipin/RoundedCorner

For example, Tab 1 is a no-fillet effect, and the other three tabs correspond to three different methods.

Three ways to achieve fillet effect with ios_ view and comparison

Related Article

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.