Drawing a transparent circle on top of a UIImage - iPhone SDK

前端 未结 4 536
轮回少年
轮回少年 2021-02-11 07:19

I am having a lot of trouble trying to find out how to draw a transparent circle on top of a UIImage within my UIImageView. Google-ing gives me clues, but I still can\'t find a

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-11 08:13

    One way would be to add a CAShapeLayer with a circular path, either directly to the layer of the UIImageView or as the layer of a new UIView that is added to the UIImageView.

    If you actually want to modify the image, then create a mutable copy of it by drawing it into a CGBitmapContext then creating a new image from the modified bitmap.

    CGPathRef circlePath = CGPathCreateMutable();
    CGPathAddEllipseInRect( circlePath , NULL , CGRectMake( 0,0,20,20 ) );
    CAShapeLayer *circle = [[CAShapeLayer alloc] init];
    circle.path = circlePath;
    circle.opacity = 0.5;
    [myImageView.layer addSublayer:circle];
    CGPathRelease( circlePath );
    [circle release];
    

提交回复
热议问题