zoukankan      html  css  js  c++  java
  • xamarin.ios 实现圆形进度条

    using System;
    using UIKit;
    using System.Drawing;
    using CoreAnimation;
    
    namespace PMM
    {
        public class ProgressCircleView : UIView
        {
            protected CAShapeLayer _progressCircle;
            protected CAShapeLayer PageGrayCircle;
            public override CoreGraphics.CGRect Bounds {
                get 
                {
                    return base.Bounds;
                }
                set {
                    base.Bounds = value;
                    GrayCircle ();
                }
            }
    
            public ProgressCircleView ()
            {
                GrayCircle ();
            }
    
            /// <summary>
            /// Redraws the progress circle. If the circle is already on the screen, it removes that one and creates a new one using the 
            /// current properties of the view
            /// </summary>
            void RedrawCircle ()
            {
                
                var centerPoint = new PointF ((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 = new CAShapeLayer ();
    
                _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);
    
    
            }
            void GrayCircle()
            {
                if (_progressCircle != null && _progressCircle.SuperLayer != null) {
                    _progressCircle.RemoveFromSuperLayer ();
                }
                var centerPoint = new PointF ((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 = new CAShapeLayer ();
    
                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 void UpdateProgress(float progressPercent) {
                _progressCircle.StrokeEnd = progressPercent;
                PageGrayCircle.StrokeEnd = 1 - progressPercent;
            }
        }
    }
  • 相关阅读:
    设计模式学习笔记(1)——简单工厂模式
    BarTender怎样同时打印自动日期和流水号?
    BarTender安装常见问题集结
    Windows更新导致的打印问题
    BarTender中如何为称重设备设置秤显示?
    BarTender中如何调整数据输入表单的大小?
    BarTender 2016如何导出模板为pdf文件?
    ABBYY PDF Transformer+安装教程
    ABBYY PDF Transformer+ 给你好看
    ABBYY PDF Transformer+功能概述
  • 原文地址:https://www.cnblogs.com/qinhe/p/5255829.html
Copyright © 2011-2022 走看看