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