0
我写了一个简单的drawRect,用于绘制圆圈,放下阴影并用蓝色填充。我已经成功地画了一个圆圈并填充为蓝色,但是我的影子没有生效。直到我的drawRect有维[[CustomButton alloc] initWithFrame:CGRectMake(0,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
谢谢
它的工作。谢谢。 – slysid