2

以下のように、サブクラス化された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?
   }
4

2 に答える 2

4

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-18T03:19:06.700 に答える
1

Quartz2Dシャドウガイドを参照してください。

CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);
于 2010-01-18T00:27:22.960 に答える