我正在使用以下代码绘制一个带有白色描边和由属性指定的颜色的圆形:
- (void)drawRect:(CGRect)rect {
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextClearRect(contextRef, rect);
// Set the border width
CGContextSetLineWidth(contextRef, 1.5);
// Set the circle fill color to GREEN
CGFloat red, green, blue, alpha;
BOOL didConvert = [_routeColor getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBFillColor(contextRef, red, green, blue, 1.0);
// Set the cicle border color to BLUE
CGContextSetRGBStrokeColor(contextRef, 255.0, 255.0, 255.0, 1.0);
// Fill the circle with the fill color
CGContextFillEllipseInRect(contextRef, rect);
// Draw the circle border
CGContextStrokeEllipseInRect(contextRef, rect);
}
我得到的图像看起来像这样:
我该如何去除黑色部分?
CGContextSetRGBFillColor
和CGContextSetRGBStrokeColor
的调用。改为以下操作:[_routeColor setFill]; [[UIColor whiteColor] setStroke];
。另外,颜色值需要在0.0 - 1.0范围内,所以你所有的255.0值都应该是1.0。 - rmaddy