在 Xamarin.iOS (Xamarin Monotouch) 中绘制圆圈以图形方式显示进度 [英] Drawing Circles In Xamarin.iOS (Xamarin Monotouch) for Showing Progress Graphically

查看:16
本文介绍了在 Xamarin.iOS (Xamarin Monotouch) 中绘制圆圈以图形方式显示进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我对 Xamarin World 非常陌生,并且不熟悉它的控件.我想在我的单点触控应用程序中添加圆圈以显示工作进度.为了显示进度,我必须在圆圈中标记一个弧.如果可能,任何人都可以帮助我提供示例代码.等待答案,非常感谢.

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.

推荐答案

using System;
    using UIKit;
    using CoreGraphics;

    namespace CircleTest.Touch
    {
        public class CircleGraph : UIView
        {
            int _radius = 10;
            int _lineWidth = 10;
            nfloat _degrees = 0.0f;
            UIColor _backColor = UIColor.FromRGB(46, 60, 76);
            UIColor _frontColor = UIColor.FromRGB(234, 105, 92);
            //FromRGB (234, 105, 92);

        public CircleGraph (CGRect frame, int lineWidth, nfloat degrees)
        {
            _lineWidth = lineWidth; 
            _degrees = degrees; 
            this.Frame = new CGRect(frame.X, frame.Y, frame.Width, frame.Height);
            this.BackgroundColor = UIColor.Clear; 

        }

        public CircleGraph (CGRect frame, int lineWidth, UIColor backColor, UIColor frontColor)
        {
            _lineWidth = lineWidth;
            this.Frame = new CGRect(frame.X, frame.Y, frame.Width, frame.Height);
            this.BackgroundColor = UIColor.Clear;

        }

        public override void Draw (CoreGraphics.CGRect rect)
        {
            base.Draw (rect);

            using (CGContext g = UIGraphics.GetCurrentContext ()) {
                _radius = (int)( (this.Bounds.Width) / 3) - 8;
                DrawGraph(g, this.Bounds.GetMidX(), this.Bounds.GetMidY());
            };
        }

        public void DrawGraph(CGContext g,nfloat x0,nfloat y0) {
            g.SetLineWidth (_lineWidth);

            // Draw background circle
            CGPath path = new CGPath ();
            _backColor.SetStroke ();
            path.AddArc (x0, y0, _radius, 0, 2.0f * (float)Math.PI, true);
            g.AddPath (path);
            g.DrawPath (CGPathDrawingMode.Stroke);

            // Draw overlay circle
            var pathStatus = new CGPath ();
            _frontColor.SetStroke ();
            pathStatus.AddArc(x0, y0, _radius, 0, _degrees * (float)Math.PI, false);
            g.AddPath (pathStatus);
            g.DrawPath (CGPathDrawingMode.Stroke);
        }
    }
}

实际上这就是我真正应该做的.它对我有用

Actually this is what iam actually supposed to do. Its working for me

这就是它的样子.你可以像类文件一样创建它,你可以简单地分配给一个 UIView.如需更多参考,您可以使用此示例项目 Pi Graph

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

: Draw 方法最初将 View.Frame x,y 传递给 DrawGraph方法.这应该是 View.Bounds (上面修改以反映这一点).请记住,框架 x,y 参考包含的超视图,而边界参考当前视图.如果在 0,0 处添加视图,这会起作用,但是一旦您开始在 UI 中移动,它就会消失.当绘制弧线时,传递给 AddArc 的 x,y 值需要参考当前视图而不是父超级视图.

: The Draw method originally passed the View.Frame x,y to the DrawGraph method. This should be View.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.

这篇关于在 Xamarin.iOS (Xamarin Monotouch) 中绘制圆圈以图形方式显示进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆