iOS UIView性能最优的设计圆角并且绘制边框颜色

//以给cell切圆角为例
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = CGRectMake(0, 0, cellWidth, cellHeight); CAShapeLayer *borderLayer = [CAShapeLayer layer]; borderLayer.frame = CGRectMake(0, 0, cellWidth, cellHeight); borderLayer.lineWidth = 1.f; borderLayer.strokeColor = lineColor.CGColor; borderLayer.fillColor = [UIColor clearColor].CGColor; UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, cellWidth, cellHeight) cornerRadius:cornerRadius]; maskLayer.path = bezierPath.CGPath; borderLayer.path = bezierPath.CGPath; [cell.contentView.layer insertSublayer:borderLayer atIndex:0]; [cell.contentView.layer setMask:maskLayer]; }

 

posted @ 2017-05-02 15:50  J-Vijay  阅读(1784)  评论(0编辑  收藏  举报