下面的代码很好地创建了一个由 CGRect (rectRect) 定义的圆角矩形。
它填充得很好,但我没有中风。任何想法为什么我看不到中风?
-(void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(ctx, 0, 0, 0, 0.4);
CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1);
CGContextSetLineWidth(ctx, 4.0);
float fw, fh;
rect = rectRect;
float ovalWidth = 12;
float ovalHeight = 12;
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(ctx, rect);
return;
}
CGContextTranslateCTM (ctx, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM (ctx, ovalWidth, ovalHeight);
fw = CGRectGetWidth (rect) / ovalWidth;
fh = CGRectGetHeight (rect) / ovalHeight;
CGContextMoveToPoint(ctx, fw, fh/2);
CGContextAddArcToPoint(ctx, fw, fh, fw/2, fh, 1);
CGContextAddArcToPoint(ctx, 0, fh, 0, fh/2, 1);
CGContextAddArcToPoint(ctx, 0, 0, fw/2, 0, 1);
CGContextAddArcToPoint(ctx, fw, 0, fw, fh/2, 1);
CGContextClosePath(ctx);
CGContextFillPath(ctx);
CGContextStrokePath(ctx);
}