您的位置:首页 > 其它

不使用layer的masksToBounds和cornerRadius来设置圆角

2016-09-21 14:48 471 查看
<pre name="code" class="objc">不使用layer的masksToBounds和cornerRadius来设置圆角:
/** 使用CoreGraphics和UIbezierPath */UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addClip];[imageView drawRect:imageView.bounds];imageView.image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();
/** 使用CAShapeLayer和UIBezierPath 性能好、渲染快速 */
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:imageView.bounds.size];CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];maskLayer.frame = imageView.bounds;maskLayer.path = maskPath.CGPath;imageView.layer.mask = maskLayer;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐