不使用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;
相关文章推荐
- 裁切图像设置圆角图像,不使用控件的layer.cornerRadius属性
- 不使用cornerRadius设置图片圆角
- 【iOS】在不使用cornerRadius的情况下,设置图像为圆角
- 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可
- iOS CoreAnimation (六) layer属性:阴影相关,边框、圆角,masksToBounds
- iOS UI控件的圆角设置,layer属性简单使用
- 如何高性能的给UIImageView加个圆角?(不准说layer.cornerRadius!)
- IOS如何给VIEW设置2个圆角?set cornerRadius for only top-left and top-right corner of a UIVIEW
- iOS切圆角的方式 第一种方法:通过设置layer的属性 最简单的一种,但是很影响性能,一般在正常的开发中使用很少. UIImageView *imageView = [[UIImag
- 还在用cornerRadius设置圆角么?快来试试效率更高的新方法。
- 设置layer.cornerRadius后变卡怎么解决
- 设置UIView圆角 cornerRadius 圆角有性能问题,用贝塞尔曲线代替
- 如何高性能的给UIImageView加个圆角?(不准说layer.cornerRadius!)
- 阴影,图层蒙板及圆角(当和maskToBounds一起使用时)影响TableView的性能
- iOS10 Xcode8 设置圆角 cornerRadius 后,控件不展示
- 如何高性能的给UIImageView加个圆角?(不准说layer.cornerRadius!)
- how to set cornerRadius for only top-left and top-right corner of a UIView?
- How to set globe layer cache properties(如何设置globe图层的缓存属性)
- View Frame、bounds、clipsToBounds、masksToBounds
- instance method '-setMasksToBounds:' not found (return type defaults to 'id')