我用一个白色笔画和一个由属性指定的颜色绘制一个圆圈,使用这段代码:
- (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].
注意,只有在创建视图时,才需要设置背景颜色一次.
原文地址:https://www.jb51.cc/iOS/336290.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。