usingSystem;usingUIKit;usingSystem.Drawing;usingcoreanimation;namespacepmm{ Public classProgresscircleview:uiview {protectedCashapelayer _progresscircle; protectedCashapelayer pagegraycircle; Public Overridecoregraphics.cgrect Bounds {Get { return Base. Bounds; } Set { Base. Bounds =value; Graycircle (); } } PublicProgresscircleview () {graycircle (); } /// <summary> ///redraws the Progress Circle. If the circle is already on the screens, it removes that one and creates a new one using the///Current properties of the view/// </summary> voidredrawcircle () {varCenterPoint =NewPointF ((float) This. Bounds.width, (float) This. Bounds.height); Uibezierpath Circlepath= Uibezierpath.fromarc (CenterPoint, This. Bounds.width *. 5f, (float)(-.5* Math.PI), (float)(1.5* Math.PI),true); _progresscircle=NewCashapelayer (); _progresscircle.path=Circlepath.cgpath; _progresscircle.strokecolor=UIColor.Red.CGColor; _progresscircle.fillcolor=UIColor.Clear.CGColor; _progresscircle.linewidth=5f; _progresscircle.linecap=Cashapelayer.capround; _progresscircle.strokestart=0f; _progresscircle.strokeend=0f; This. Layer.addsublayer (_progresscircle); } voidgraycircle () {if(_progresscircle! =NULL&& _progresscircle.superlayer! =NULL) {_progresscircle.removefromsuperlayer (); } varCenterPoint =NewPointF ((float) This. Bounds.width, (float) This. Bounds.height); Uibezierpath Circlepath= Uibezierpath.fromarc (CenterPoint, This. Bounds.width *. 5f, (float)(1.5* Math.PI), (float)(-.5* Math.PI),false); Pagegraycircle=NewCashapelayer (); Pagegraycircle.path=Circlepath.cgpath; Pagegraycircle.strokecolor=UIColor.Gray.CGColor; Pagegraycircle.fillcolor=UIColor.Clear.CGColor; Pagegraycircle.linewidth=4f; Pagegraycircle.linecap=Cashapelayer.capround; Pagegraycircle.strokestart=0f; Pagegraycircle.strokeend=0f; This. Layer.addsublayer (pagegraycircle); Redrawcircle (); } /// <summary> ///Updates the Progress Circle. /// </summary> /// <param name= "Progresspercent" >The percentage of the progress. Should be a value between 0.0 and 1.0</param> Public voidUpdateProgress (floatprogresspercent) {_progresscircle.strokeend=progresspercent; Pagegraycircle.strokeend=1-progresspercent; } }}
Xamarin.ios Implementing a circular progress bar