As I'm very new to Xamarin World and new to its controls. I would like to add Circles to Show Work Progress in my mono touch app. For showing Progress I have to mark an Arc in the circle. And if possible any one can help with me a sample code. Awaiting an answer, Thanks a lot in advance.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Drawing a circle on a GLContext isn't that hard to do and is the same as you would do in Objective-C or Swift.
I assume you want to create your own view which you can reuse. To do so, simply inherit from
UIView
:Now to draw anything in your new custom view you want to override the
Draw
method:To draw stuff you need to get hold of the current context from
UIGraphics
, which can be done like so:The
CGContext
you get back, is very similar toCanvas
on Android for instance. It has helper methods to draw arcs, circles, rectangles, points and much more.So to draw a simple circle in that context, you do:
So combine everything you get:
That is it! Well, not exactly, this is where you need to start think of how you want to draw your progress indicator. What I think would probably work is:
gctx.AddArc()
, which can take an angle and draw an arc.To draw a string you will need to convert your string to a
NSAttributedString
then useCTLine
to draw the text like:Actually this is what iam actually supposed to do. Its working for me
This is how it look like. U can create it like a class file and simply u can assign to a UIView. For more reference you can use this sample project Pi Graph
[EDIT]: The
Draw
method originally passed theView.Frame
x,y to theDrawGraph
method. This should beView.Bounds
(modified above to reflect this). Remember that the frame x,y is in reference to the containing superview and bounds is referenced to the current view. This would have worked if the view was added at 0,0 but once you start moving around the UI it disappears. When the arcs are drawn the values for x,y passed to AddArc need to be in reference to the current view not the parent superview.Minor alterations to the answer provided by @SARATH as copying and pasting did not yield the desired result.
Changed _degrees to _percentComplete
Fixed overload constructor for changing colors by adding a param for percentComplete and added missing member variable assignments for _backColor and _frontColor
Added constant float value for drawing a full circle (FULL_CIRCLE)
Multiply _percentComplete by FULL_CIRCLE to get the end angle for both arcs (with different directions)
Calculation of the radius
Example
CircleGraph at 75%