Trying to draw a filled circle but it has got a black background

testing

I want to draw a circle with a certain color, which fills out the whole circle. I'm using auto layout to determine the size of the circle. If I'm doing this the circle is drawn but the background color is black. It should be a clear color so that the background can shine through and the circle should be round of course. This is my code in C#, but it isn't that much difference to 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);
        }
    }
}

The circle is slightly smaller than the UIView so that is drawn correctly not touching the edges (and so cutting of some parts).

But the background is black as you can see here: circle with black background

How can I draw a filled circle?

testing

Seems that I have to put this

this.BackgroundColor = UIColor.Clear;

into the constructor. Now I don't have a black background anymore.

It seems also that it is sufficient to use these lines of code for drawing:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Drawing a filled circle in a canvas on mouseclick

From Dev

Draw a transparent circle onto a filled android canvas

From Dev

Draw Point or filled in circle

From Dev

Draw a circle filled with random color sqares on canvas

From Dev

How to draw a filled circle on a video frame using matlab

From Dev

PNG in ImageView has black background

From Dev

Transparent AlertDialog has black background

From Dev

Eclipse EGit with dark background, still has black text

From Dev

CSS ONLY Animate Draw Circle with border-radius and transparent background

From Dev

Draw a filled circle with number inside

From Dev

Cannot draw a filled circle with SDL2 gfx

From Dev

Draw clockwise filled in circle

From Dev

Draw a filled circle with SDL2_gfx in C/C++

From Dev

How do I draw a filled circle using SpriteKit?

From Dev

How to draw a rectangle with black border and background transparent on Imageview?

From Dev

Trying to draw an arc over a circle using d3

From Dev

Trying to draw bitmaps on circumference of a circle, find some offset in the implementation

From Dev

How to plot a filled circle?

From Dev

filled / open circle by group

From Dev

Trying to draw a circle in Java using variable in parameters

From Dev

How to draw a filled circle on a video frame using matlab

From Dev

Draw Circle in the background of Text View, over each image in Fragment

From Dev

why is my circle filled Black even though i haven't set it to be filled

From Dev

Trying to draw circle on Laser pointer, OpenCV

From Dev

Draw a closed and filled contour

From Dev

Screen shot of container has black background instead of white

From Dev

how to draw circle with text in middle and an image as a background of the circle?

From Dev

Drawing true filled circle on an image

From Dev

iOS app has a black background and the app icon overflows to the edges

Related Related

  1. 1

    Drawing a filled circle in a canvas on mouseclick

  2. 2

    Draw a transparent circle onto a filled android canvas

  3. 3

    Draw Point or filled in circle

  4. 4

    Draw a circle filled with random color sqares on canvas

  5. 5

    How to draw a filled circle on a video frame using matlab

  6. 6

    PNG in ImageView has black background

  7. 7

    Transparent AlertDialog has black background

  8. 8

    Eclipse EGit with dark background, still has black text

  9. 9

    CSS ONLY Animate Draw Circle with border-radius and transparent background

  10. 10

    Draw a filled circle with number inside

  11. 11

    Cannot draw a filled circle with SDL2 gfx

  12. 12

    Draw clockwise filled in circle

  13. 13

    Draw a filled circle with SDL2_gfx in C/C++

  14. 14

    How do I draw a filled circle using SpriteKit?

  15. 15

    How to draw a rectangle with black border and background transparent on Imageview?

  16. 16

    Trying to draw an arc over a circle using d3

  17. 17

    Trying to draw bitmaps on circumference of a circle, find some offset in the implementation

  18. 18

    How to plot a filled circle?

  19. 19

    filled / open circle by group

  20. 20

    Trying to draw a circle in Java using variable in parameters

  21. 21

    How to draw a filled circle on a video frame using matlab

  22. 22

    Draw Circle in the background of Text View, over each image in Fragment

  23. 23

    why is my circle filled Black even though i haven't set it to be filled

  24. 24

    Trying to draw circle on Laser pointer, OpenCV

  25. 25

    Draw a closed and filled contour

  26. 26

    Screen shot of container has black background instead of white

  27. 27

    how to draw circle with text in middle and an image as a background of the circle?

  28. 28

    Drawing true filled circle on an image

  29. 29

    iOS app has a black background and the app icon overflows to the edges

HotTag

Archive