Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 problem 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!

like image 938
Rits Avatar asked May 29 '10 15:05

Rits


1 Answers

Use CGContextSetBlendMode() before you draw the rect.

like image 126
NSResponder Avatar answered Oct 03 '22 11:10

NSResponder