How to create a custom circled UIView with two different colors?

914 views Asked by At

Is there a way to create a circled UIView with two different colors, like this:

circle example

The circle should be divided as you can see on the image (border).

1

There are 1 answers

0
Daniel On BEST ANSWER

Subclass UIView and implement the drawRect: method.

Here is code to draw a circle to get you started:

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddEllipseInRect(ctx, rect);
    CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor blueColor] CGColor]));
    CGContextFillPath(ctx);
}

also, take a look at how to draw part of a circle