如何使用CoreGraphics填充带有alpha颜色的矩形? [英] How can I fill a rect with an alpha color using CoreGraphics?

查看:134
本文介绍了如何使用CoreGraphics填充带有alpha颜色的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的drawRect方法中,我正在绘制一个PNG图像。最重要的是,我想绘制一个20%alpha颜色的矩形,如下所示:

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);

问题是,alpha属性似乎被忽略了。根本不应用alpha,只绘制一个黑色矩形。我怎样才能解决这个问题?提前致谢!

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!

推荐答案

在绘制之前使用 CGContextSetBlendMode() rect。

Use CGContextSetBlendMode() before you draw the rect.

这篇关于如何使用CoreGraphics填充带有alpha颜色的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆