开发者

How can I fill a rect with an alpha color using CoreGraphics?

开发者 https://www.devze.com 2023-01-01 06:22 出处:网络
In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this:

In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this:

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

The prob开发者_JAVA技巧lem is, that the alpha property seems to get ignored. No alpha is applied at all, just a black rectangle is drawn. How can I fix this? Thanks in advance!


Use CGContextSetBlendMode() before you draw the rect.


Set your view background color to transparent… It should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消