ios – 透明背景UIView drawRect圆

前端之家收集整理的这篇文章主要介绍了ios – 透明背景UIView drawRect圆前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用一个白色笔画和一个由属性指定的颜色绘制一个圆圈,使用这段代码
  1. - (void)drawRect:(CGRect)rect {
  2.  
  3. CGContextRef contextRef = UIGraphicsGetCurrentContext();
  4.  
  5. CGContextClearRect(contextRef,rect);
  6.  
  7. // Set the border width
  8. CGContextSetLineWidth(contextRef,1.5);
  9.  
  10. // Set the circle fill color to GREEN
  11. CGFloat red,green,blue,alpha;
  12. BOOL didConvert = [_routeColor getRed:&red green:&green blue:&blue alpha:&alpha];
  13.  
  14. CGContextSetRGBFillColor(contextRef,red,1.0);
  15.  
  16. // Set the cicle border color to BLUE
  17. CGContextSetRGBStrokeColor(contextRef,255.0,1.0);
  18.  
  19. // Fill the circle with the fill color
  20. CGContextFillEllipseInRect(contextRef,rect);
  21.  
  22. // Draw the circle border
  23. CGContextStrokeEllipseInRect(contextRef,rect);
  24. }

我得到的图像看起来像这样:

如何清除黑色?

解决方法

将视图的backgroundColor设置为[UIColor clearColor].

注意,只有在创建视图时,才需要设置背景颜色一次.

猜你在找的iOS相关文章