//设置分组圆角

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

if (indexPath.section==1) {

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

CGFloat cornerRadius = 6.f;

cell.backgroundColor = UIColor.clearColor;

CAShapeLayer *layer = [[CAShapeLayer alloc] init];

CGMutablePathRef pathRef = CGPathCreateMutable();

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

if (indexPath.row == 0 && indexPath.row == [collectionView numberOfItemsInSection: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));

} else if (indexPath.row == [collectionView numberOfItemsInSection:indexPath.section]-1 || (indexPath.row == 0 && indexPath.row == [collectionView numberOfItemsInSection: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);

}

layer.path = pathRef;

CFRelease(pathRef);

//颜色修改

layer.fillColor = [UIColor whiteColor].CGColor;

layer.strokeColor=[UIColor clearColor].CGColor;

UIView *testView = [[UIView alloc] initWithFrame:bounds];

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

testView.backgroundColor = [UIColor redColor];

cell.backgroundView = testView;

}

}

}