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]; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM