原文地址:http://www.cocoachina.com/ios/20150803/12873.html
最基本方法
aImageView.layer.cornerRadius = aImageView.frame.size.width/2.0;
aImageView.layer.masksToBounds = YES;高级方法(UIBezierPath)
CAShapeLayer *layer = [CAShapeLayer layer];
UIBezierPath *aPath = [UIBezierPath bezierPathWithOvalInRect:aImageView.bounds];
layer.path = aPath.CGPath;
aImageView.layer.mask = layer;
+ (UIBezierPath *)bezierPathWithOvalInRect:(CGRect)rect 这个方法根据传入的rect矩形参数绘制一个内切曲线。
当传入的rect是一个正方形时,绘制的图像是一个内切圆;当传入的rect是一个长方形时,绘制的图像是一个内切椭圆。
本文介绍了两种在iOS中创建圆形图片视图的方法:一种是通过简单地设置UIView的cornerRadius属性并启用maskToBounds属性来实现;另一种是利用CAShapeLayer结合UIBezierPath绘制圆形遮罩来达到目的。当需要精确控制边界时,第二种方法更为灵活。

被折叠的 条评论
为什么被折叠?



