对cell的最上边和最下边左圆角处理

来源:互联网 发布:ipadpro手写笔软件 编辑:程序博客网 时间:2024/04/27 21:22

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if ([cell respondsToSelector:@selector(tintColor)]) {

        if (tableView == self.tableView) {

            CGFloat cornerRadius = 15.f;

            cell.backgroundColor = UIColor.clearColor;

            CAShapeLayer *layer = [[CAShapeLayeralloc] init];

            CGMutablePathRef pathRef = CGPathCreateMutable();

            CGRect bounds = CGRectInset(cell.bounds, 10, 0);

            BOOL addLine = NO;

            if (indexPath.row ==0 && indexPath.row == [tableViewnumberOfRowsInSection: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 = [UIColorcolorWithWhite:1.falpha:0.8f].CGColor;

            

            if (addLine == YES) {

                CALayer *lineLayer = [[CALayeralloc] init];

                CGFloat lineHeight = (1.f / [UIScreenmainScreen].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 = [[UIViewalloc] initWithFrame:bounds];

            [testView.layer insertSublayer:layer atIndex:0];

            testView.backgroundColor = UIColor.clearColor;

            cell.backgroundView = testView;

        }

    }

}

0 0