- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat cornerRadius =10.0;
CGRect bounds = cell.bounds;
// 每区行数
NSInteger numberOfRows = [tableView numberOfRowsInSection:indexPath.section];
// 区头
UIView *view = [self tableView:tableView viewForHeaderInSection:indexPath.section];
//绘制曲线
UIBezierPath *bezierPath = nil;
if (indexPath.row == 0 && numberOfRows == 1) {
// 一个区只有一行cell
if (view != nil) {
// 有区头:左下,右下为圆角
bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
}else{
//四个角都为圆角
bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
}
} else if (indexPath.row == 0) {
// 某个区的第一行
if (view != nil) {
// 有区头:为矩形
bezierPath = [UIBezierPath bezierPathWithRect:bounds];
}else{
//左上、右上角为圆角
bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
}
} else if (indexPath.row == numberOfRows - 1) {
//某个区的最后一行:左下、右下角为圆角
bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
} else {
//某个区的中间行:为矩形
bezierPath = [UIBezierPath bezierPathWithRect:bounds];
}
cell.backgroundColor = [UIColor clearColor];
//新建一个layer层,设置填充色和边框颜色
CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = bezierPath.CGPath;
layer.fillColor = [UIColor whiteColor].CGColor;
layer.strokeColor = [UIColor whiteColor].CGColor;
//将layer层添加到cell.layer中,并插到最底层
[cell.layer insertSublayer:layer atIndex:0];
}
tableview 分区圆角(包含区头)
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- - (void)tableView:(UITableView*)tableViewwillDisplayCell:...
- 参考文章:https://zhuanlan.zhihu.com/p/269559400 - (void)table...
- tableView时常有一个效果,就是当cell在section的第一个位置或者最后一行时,第一个cell左上角和...
- 最近项目UI需求tableViewCell 带圆角边框,自己写了下像平常那样去设置圆角边框行不通网上差了一下自己又...
- 先看以下的效果图 在UITableViewDelegate的willDisplayCell方法中,通过UIBezi...