优雅设置cell的圆角

转自:http://www.jianshu.com/p/2df0ea05c005

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGRect cellBounds = CGRectMake(0, 0, cellWidth, cellHeight);
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = cellBounds;
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:cellBounds cornerRadius:cornerRadius];
    maskLayer.path = bezierPath.CGPath;
    [cell.layer setMask:maskLayer];
}

你可能感兴趣的:(IOS开发,OC)