0

円を描き、影を落とし、青で塗りつぶすという意図で単純な drawRect を書きました。円を描いて青で塗りつぶすことに成功しましたが、影は効果がありません。円をなでると塗りつぶしの代わりに、影が円の内側にあり、塗りつぶし中に塗りつぶしの色で描かれていることがわかります

私の drawRect への rect にはディメンションがあります [[CustomButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];

@implementation CustomButton

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
    [self setBackgroundColor:[UIColor clearColor]];
}
return self;
}

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef colorRef = [[UIColor blueColor] CGColor];
CGContextSetStrokeColorWithColor(context, colorRef);
CGContextSetFillColorWithColor(context, [[UIColor blueColor] CGColor]);


CGRect buttonRect = CGRectInset(rect, 3, 3);

CGPoint centerPoint = CGPointMake(CGRectGetMidX(buttonRect  ),     CGRectGetMidY(buttonRect));
CGFloat radius = CGRectGetWidth(buttonRect) / 2;

CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(15.0, 20.0), 1.0);
CGContextAddArc(context, centerPoint.x, centerPoint.y, radius, 0, 2*M_PI, 1);
CGContextClip(context);
CGContextFillRect(context, buttonRect);
CGContextRestoreGState(context);


CGColorRelease(colorRef);

}

@end

ありがとうございました

4

1 に答える 1