我在我的子类uiview中画了一个简单的圆,如下所示。如何在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?
}发布于 2010-01-18 11:19:07
要理解slf的答案,您可以将上面的代码替换为:
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(ctx);
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); // white color
CGContextSetShadow(ctx, CGSizeMake(2.0f, 2.0f), 2.0f);
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();
}这将创建一个向下偏移2个像素的阴影,它位于圆的右侧,模糊程度为2个像素。您可以更改这些值以创建所需的效果。如果要将发光效果添加到此绘图中,还可以将CGContextSetShadowWithColor()与黑色以外的其他颜色一起使用。
发布于 2010-01-18 08:27:23
请参阅Quartz2D Shadows指南。
CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);https://stackoverflow.com/questions/2083201
复制相似问题