为什么CGContextSetShadowWithColor也会改变当前的填充颜色?

时间:2012-11-19 20:53:20

标签: ios macos core-graphics

我正在覆盖-drawRect:来绘制一些自定义视图。通常,我正在绘制带有阴影的填充圆角矩形贝塞尔曲线路径。但是,我遇到了一个恼人的问题:当我设置阴影颜色时,填充颜色也会变为相同的颜色!

这是Core Graphics中的错误还是我错过了什么?这是我的代码示例,我正在尝试绘制带阴影的路径。 translucentBlackhighlight是两个不同的UIColor对象,但绘制的是圆角矩形,其中突出显示颜色以及高光颜色中的阴影。

UIBezierPath* blackTranslucentRoundedRectPath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(CGRectGetMinX(frame) + 5, CGRectGetMinY(frame) + 5, CGRectGetWidth(frame) - 10, CGRectGetHeight(frame) - 10) cornerRadius: 8];
CGContextSetShadowWithColor(context, highlightOffset, highlightBlurRadius, highlight.CGColor);
[translucentBlack setFill];
[blackTranslucentRoundedRectPath fill];

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:2)

发生的事情是您可以通过半透明黑色看到您的高光颜色。将translucentBlack更改为任何非透明颜色(使其alpha等于1.0),您应该没问题。