我用一个白色笔画和一个由属性指定的颜色绘制一个圆圈,使用这段代码:
- - (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,1.0);
- // Set the cicle border color to BLUE
- CGContextSetRGBStrokeColor(contextRef,255.0,1.0);
- // Fill the circle with the fill color
- CGContextFillEllipseInRect(contextRef,rect);
- // Draw the circle border
- CGContextStrokeEllipseInRect(contextRef,rect);
- }
我得到的图像看起来像这样:
如何清除黑色?
解决方法
将视图的backgroundColor设置为[UIColor clearColor].
注意,只有在创建视图时,才需要设置背景颜色一次.