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

2

5

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!

Overabundance answered 29/5, 2010 at 15:23 Comment(0)
L
7

Use CGContextSetBlendMode() before you draw the rect.

Luciusluck answered 30/5, 2010 at 21:15 Comment(1)
Yes, that did the trick! Thanks. I used a similar function: UIRectFillUsingBlendMode(rect, kCGBlendModeNormal);Overabundance
O
0

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

Overturn answered 12/6, 2015 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.