How to fill a rectangle with alpha color using CoreGraphics?

In my drawRect method, I draw a PNG image. In addition, I want to draw a rectangle with 20% alpha color, for example:

[[UIColor colorWithWhite:0.0 alpha:0.2] set]; UIRectFill(rect); 

The problem is that the alpha property seems to be ignored. Alpha is not applied at all, just a black rectangle is drawn. How can i fix this? Thanks in advance!

+4
source share
2 answers

Use CGContextSetBlendMode() before drawing a rectangle.

+7
source

Set the background color of your view to transparent ... It should work.

0
source

Source: https://habr.com/ru/post/1311303/


All Articles