Drawing a circle in GLContext is not that difficult, and it's the same thing you would do in Objective-C or Swift.
I assume that you want to create your own view, which you can reuse. To do this, simply inherit from UIView :
public class CircleView : UIView { }
Now, to draw something in a new user view, you want to override the Draw method:
public override void Draw(RectangleF rect) { base.Draw(rect);
To draw material, you need to get the current context from UIGraphics , which can be done as follows:
using (var gctx = UIGraphics.GetCurrentContext()) {
The returned CGContext is very similar to Canvas on Android, for example. It has helper methods for drawing arcs, circles, rectangles, points, and more.
To draw a simple circle in this context, you do:
gctx.SetFillColor(UIColor.Cyan.CGColor); gctx.AddEllipseInRect(rect);
So combine everything you get:
public class CircleView : UIView { public override Draw(RectangleF rect) { base.Draw(rect); using (var gctx = UIGraphics.GetCurrentContext()) { gctx.SetFillColor(UIColor.Cyan.CGColor); gctx.AddEllipseInRect(rect); } } }
That's all! Well, not really, that's where you need to start thinking about how you want to draw a progress indicator. I think that will probably work:
- Draw the back surface
- Draw the borders
- Calculate the percentage of progress
- Use degrees to create an arc using
gctx.AddArc() , which can take an angle and draw an arc. - Draw a percentage as a line in the middle
To draw a string, you will need to convert your string to NSAttributedString , then use CTLine to draw the text as follows:
using(var line = new CTLine(nsAttrString)) line.Draw(gctx);