我想绘制一个椭圆形的UIImageView
。我试着画画,但我找不到答案。我展示了大部分圆形或圆形。
enter link description here
我试试这个,但这是行不通的
#import <QuartzCore/QuartzCore.h>`
CALayer *imageLayer = YourImageview.layer;
[imageLayer setCornerRadius:5];
[imageLayer setBorderWidth:1];
[imageLayer setMasksToBounds:YES];
最佳答案
如果要绘制椭圆形的 ImageView ,请按照以下步骤操作:
使用 bezierPathWithOvalInRect 创建 UIBezierPath
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:YOUR_RECT];
使用CAShapeLayer 创建 mask 层
CAShapeLayer *maskLayer = [CAShapeLayer layer];
现在将贝塞尔曲线路径设置为 mask 层的路径
maskLayer.path = path.CGPath;
然后我们将用我们自己的 mask 层 mask 我们的 View 。
YourImageview.layer.mask = maskLayer;
就是这样。试试吧。
关于ios - 如何在 UIImageview 中绘制椭圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23779116/