我画一个白色的中风和使用此代码由属性指定颜色的圆圈:透明背景的UIView的drawRect圈
- (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];'。 FYI - 颜色值需要在0.0 - 1.0的范围内,因此所有的255.0值都应该为1.0。 – rmaddy