开发者

iphone drow shadow on circle

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
   {
     CGCo开发者_StackOverflowntextRef 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?
   }


To follow on slf's answer, you'd replace the code above with:

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

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.


See Quartz2D Shadows guide.

CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜