为你的tableView的自定义cell加上圆角
来源:互联网 发布:java程序员面试问题 编辑:程序博客网 时间:2024/06/01 07:58
有的时候自己自定义了一个cell,这个cell是撑满全屏的,但是有些时候我们想要这个cell距左边10 据右边10的宽度处显示圆角,而不是整个cell
那你就需要tableView的代理方法:
#pragma mark - #pragma mark 设置圆角- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if ([cell respondsToSelector:@selector(tintColor)]) { if (tableView == self.tableView) { CGFloat cornerRadius = 5.0f; cell.backgroundColor = UIColor.clearColor; CAShapeLayer *layer = [[CAShapeLayer alloc] init]; CGMutablePathRef pathRef = CGPathCreateMutable(); CGRect bounds = CGRectInset(cell.bounds, 5, 0); BOOL addLine = NO; if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) { CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius); } else if (indexPath.row == 0) { CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds)); CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius); CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius); CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds)); addLine = YES; } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) { CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds)); CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius); CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius); CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds)); } else { CGPathAddRect(pathRef, nil, bounds); addLine = YES; } layer.path = pathRef; CFRelease(pathRef); layer.fillColor = [UIColor clearColor].CGColor; if (addLine == YES) { CALayer *lineLayer = [[CALayer alloc] init]; CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale); lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight); lineLayer.backgroundColor = tableView.separatorColor.CGColor; [layer addSublayer:lineLayer]; } UIView *testView = [[UIView alloc] initWithFrame:bounds]; [testView.layer insertSublayer:layer atIndex:0]; testView.backgroundColor = UIColor.clearColor; cell.backgroundView = testView; } }}
0 0
- 为你的tableView的自定义cell加上圆角
- 自定义tableView cell的删除按钮
- Swift TableView自定义Cell的高度
- tableview cell的移动
- ios 第16课 TableView 的cell的自定义《一》
- TableView里面的cell根据图片或者文字自定义高度
- IOS UI tableView 自定义cell的内容不显示
- 为你的程序加上加速键
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- TableView的Cell的重用
- ios的tableview的cell
- 点击tableView的cell弹出tableView
- iOS UITableView(四) 为tableView设置头尾视图,改变cell的宽度,cell的缩进
- tableview中cell的设置
- tableview中cell的设置
- ios自制tableview的cell
- 设置tableview的cell颜色
- java学习第五天
- 学习RecyclerView控件
- Android OPenCV 环境配置 <1>
- UIScrollView的delegate方法妙用之让UICollectionView滑动到某个你想要的位置
- 【sql查询与优化】2.给查询结果排序
- 为你的tableView的自定义cell加上圆角
- poj2752 kmp 模板题
- GDB 引起Illegal instruction: 4 错误解决办法
- 编程练习
- Linux设备模型(6)_Bus
- Fragment动态加载
- android6.0权限管理
- SyntaxHighlighter行号显示错误问题解决方案
- LeetCode 1 Two Sum