- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:@selector(tintColor)]) {
if (tableView == self.dataTableview && indexPath.section == 1) {
// 圆角弧度半径
CGFloat cornerRadius = 10.f;
// 设置cell的背景色为透明,如果不设置这个的话,则原来的背景色不会被覆盖
// cell.backgroundColor = UIColor.redColor;
cell.contentView.backgroundColor = UIColor.orangeColor;
// 这里要判断分组列表中的第一行,每组section的第一行,每组section的中间行
// BOOL addLine = NO;
// CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
if (indexPath.row == 0) {
//这里设置的是左上和右上
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.bounds;
maskLayer.path = maskPath.CGPath;
cell.layer.mask = maskLayer;
} else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
//这里设置的是左下和左下角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.bounds;
maskLayer.path = maskPath.CGPath;
cell.layer.mask = maskLayer;
} else {
}
// // view大小与cell一致
// UIView *roundView = [[UIView alloc] initWithFrame:bounds];
// // 添加自定义圆角后的图层到roundView中
// [roundView.layer insertSublayer:layer atIndex:0];
// roundView.backgroundColor = UIColor.clearColor;
// //cell的背景view
// //cell.selectedBackgroundView = roundView;
// cell.backgroundView = roundView;
//
// //以上方法存在缺陷当点击cell时还是出现cell方形效果,因此还需要添加以下方法
// UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:bounds];
// backgroundLayer.fillColor = tableView.separatorColor.CGColor;
// [selectedBackgroundView.layer insertSublayer:backgroundLayer atIndex:0];
// selectedBackgroundView.backgroundColor = UIColor.clearColor;
// cell.selectedBackgroundView = selectedBackgroundView;
}
}
}
tableview以section添加圆角
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 参考文章:https://zhuanlan.zhihu.com/p/269559400 - (void)table...
- 先看以下的效果图 在UITableViewDelegate的willDisplayCell方法中,通过UIBezi...
- - (void)tableView:(UITableView*)tableViewwillDisplayCell:...
- tableView时常有一个效果,就是当cell在section的第一个位置或者最后一行时,第一个cell左上角和...
- 运用shapeLayer 和 贝塞尔曲线 绘制圆角和阴影 - (void)tableView:(UITableVi...