如何在UIImageview中绘制椭圆形状

Ile*_*esh 0 iphone objective-c ios

我想绘制一个UIImageView椭圆形.我试图绘制,但我云找不到答案.我显示大部分圆形或圆形.
在这里输入链接描述
我试试这个,但这不起作用

#import <QuartzCore/QuartzCore.h>`
 CALayer *imageLayer = YourImageview.layer;
            [imageLayer setCornerRadius:5];
            [imageLayer setBorderWidth:1];
            [imageLayer setMasksToBounds:YES];
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

man*_*jmv 8

如果要绘制椭圆形的图像视图,请按照以下步骤操作:

  1. 使用bezierPathWithOvalInRect创建UIBezierPath

    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:YOUR_RECT];
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用CAShapeLayer创建遮罩层

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    
    Run Code Online (Sandbox Code Playgroud)
  3. 现在将bezier路径设置为遮罩层的路径

    maskLayer.path = path.CGPath;
    
    Run Code Online (Sandbox Code Playgroud)
  4. 然后我们将使用我们自己的遮罩层来掩盖我们的视图.

    YourImageview.layer.mask = maskLayer;
    
    Run Code Online (Sandbox Code Playgroud)

就这样.试试吧.