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