Sometimes, when we do cell, we meet this demand.
requirements, the first cell and the last cell of each group in the TableView display two rounded corners
When you hear the rounded corners, it is estimated that many people will think of the following two lines of code, but can not do the above effect.
Layer.cornerradius = 10;
Layer.maskstobounds = YES;
In fact, the simplest way to make the art (UI designer) to do two of these background images, and then set up the cell Cell.backgroundview is complete, this is the quickest way, but if the UI is not given, it can only be: a word to cut the picture.
When it comes to cutting pictures, think of Cashapelayer, don't ask me why, because it has a property that is path, and then think of a method in Uibezierpath
+ (Instancetype) Bezierpathwithroundedrect: (cgrect) rect byroundingcorners: (uirectcorner) Corners cornerRadii: ( Cgsize) cornerradii;
The Uirectcorner in this method is an enumeration with the following values:
Uirectcornertopleft = 1 << 0,
Uirectcornertopright = 1 << 1,
Uirectcornerbottomleft = 1 << 2,
Uirectcornerbottomright = 1 << 3,
Uirectcornerallcorners = ~0ul
This is a lot easier, on the code:
In the storyboard put a uiimageview, arbitrarily set up a picture.
////VIEWCONTROLLER.M//Set rounded corners////Created by Hqw on 16/4/20.//copyright©2016 year cormorants. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview*ImageView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Uibezierpath*path = [Uibezierpath bezierPathWithRoundedRect:self.imageView.bounds byroundingcorners:uirectcornertopleft | Uirectcornertopright Cornerradii:cgsizemake (Ten,Ten)]; Cashapelayer*layer =[Cashapelayer layer]; Layer.frame=Self.imageView.bounds; Layer.path=path. Cgpath; Self.imageView.layer.mask=layer;}@end
The results are as follows:
With this picture cell's fillet demand is solved.
To set any rounded corners of a picture