试图绘制一个实心的圆,但它有一个黑色的背景

问题描述:

我想绘制一个圆,用某种颜色填充整个圆。我使用自动布局来确定圆的大小。如果我正在做这个圆圈,但是背景颜色是黑色的。它应该是一个清晰的颜色,以便背景可以发光,并且该圆圈当然应该是圆形的。这是我在C#中的代码,但与Objective-C没有多大区别。试图绘制一个实心的圆,但它有一个黑色的背景

public class Circle : UIView 
    { 
     private UIColor color; 

     public Circle() 
     { 
      this.color = UIColor.Red; 
     } 

     public override void Draw (RectangleF rect) 
     { 
      base.Draw (rect); 

      this.BackgroundColor = UIColor.Clear; 

      float red = 0; 
      float green = 0; 
      float blue = 0; 
      float alpha = 0; 
      color.GetRGBA (out red, out green, out blue, out alpha); 

      float lineWidth = 2.0f; 
      RectangleF borderRect = RectangleF.Inflate (rect, -lineWidth/2, -lineWidth/2); 

      // Get the context 
      CGContext context = UIGraphics.GetCurrentContext(); 

      // Set the border width 
      context.SetLineWidth (lineWidth); 

      // Set the circle fill color 
      context.SetRGBFillColor (red, green, blue, alpha); 

      // Set the circle border color 
      context.SetRGBStrokeColor (red, green, blue, alpha); 

      // Fill the circle with the fill color 
      context.FillEllipseInRect (borderRect); 

      // Draw the circle border 
      //context.StrokeEllipseInRect (borderRect); 
     } 
    } 
} 

圆比UIView,使得被吸入正确地不接触边缘(和因此切割某些部分的)略小。

但背景是黑色的,你可以在这里看到: circle with black background

怎样绘制一个实心圆?

看来我得把这个

this.BackgroundColor = UIColor.Clear; 

到构造。现在我没有黑色背景了。

似乎还在于它是足够使用几行代码绘制:

context.AddEllipseInRect (rect); 
context.SetFillColor (color.CGColor); 
context.FillPath();