How to make a portion of an UIImageView transparen

2019-08-15 08:24发布

Here is a photo explanation to better illustrate what I mean:

I have two UIImageViews, with View1 being on the bottom and View2 at the top:

enter image description here enter image description here

What I would like to do accomplish is to programmatically set an area on View2 that is completely transparent (i.e. has an alpha of 0), so that this will be the end result:

enter image description here

I haven't been able to find a similar problem related to marking a part of a UIImageView transparent in the form of a shape (specifically, a circle), and was wondering how I should tackle this problem?

Thanks!

1条回答
Evening l夕情丶
2楼-- · 2019-08-15 09:03

One road you could go is CoreGraphics:

  1. Create an image context
  2. Set the clipping path you need (or just clear the circle for the "hole" after drawing)
  3. Draw the original image into the context
  4. Make an UIImage from that context
  5. Assign the image to the top UIImageView

https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/HandlingImages/Images.html#//apple_ref/doc/uid/TP40010156-CH13-SW1

查看更多
登录 后发表回答