iphone 在圆圈上绘制阴影
我在子类 uiview 中绘制了一个简单的圆圈,如下所示。如何在圆圈底部添加轻微的阴影?
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(ctx);
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); // white color
CGContextFillEllipseInRect(ctx, CGRectMake(10.0f, 10.0f, 100.0f, 100.0f)); // a white filled circle with a diameter of 100 pixels, centered in (60, 60)
UIGraphicsPopContext();
//Now what here?
}
I have a simple circle drawn in my sub classed uiview as below. How do I add a slight drowshadow on the bottom of the circe?
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(ctx);
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); // white color
CGContextFillEllipseInRect(ctx, CGRectMake(10.0f, 10.0f, 100.0f, 100.0f)); // a white filled circle with a diameter of 100 pixels, centered in (60, 60)
UIGraphicsPopContext();
//Now what here?
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要遵循 slf 的答案,您可以将上面的代码替换为:
这将创建一个在圆的右侧向下偏移 2 个像素的阴影,并带有 2 个像素的模糊。您可以更改这些值来创建您想要的效果。如果您想为此绘图添加发光效果,CGContextSetShadowWithColor() 也可以与黑色以外的颜色一起使用。
To follow on slf's answer, you'd replace the code above with:
This will create a shadow that is offset by 2 pixels down and to the right of your circle, with a blur of 2 pixels. You can alter these values to create the effect you want. CGContextSetShadowWithColor() can also be used with a different color than black, if you want to add a glow effect to this drawing.
请参阅 Quartz2D 阴影指南。
See Quartz2D Shadows guide.