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

穿精又带淫゛_ 提交于 2019-12-06 03:49:52

问题


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!


回答1:


Use CGContextSetBlendMode() before you draw the rect.




回答2:


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



来源:https://stackoverflow.com/questions/2935608/how-can-i-fill-a-rect-with-an-alpha-color-using-coregraphics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!