iOS 百分比圆环曲线swift4.0实现

 

 

 

 

import UIKit

 

class XZCircleView: UIView {

 

    let backGroundLayer = CAShapeLayer.init()///背景白色细曲线

    let progressLayer = CAShapeLayer.init()///进度真是数值曲线

    var endVale = 0.00

    var progressColor = UIColor.white.cgColor

    var backColor = "FFFFFF".toUiColorWithAlpha(0.2).cgColor

    

    

    // Only override draw() if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    override func draw(_ rect: CGRect) {

        // Drawing code

        self.initTheView(rect)

    }

 

    func initTheView(_ rect : CGRect) {

        

        // 设置百分比动画显示

//设置白色背景线

        self.backGroundLayer.frame = rect

        

        self.backGroundLayer.fillColor = UIColor.clear.cgColor

        self.backGroundLayer.lineWidth = 1

        let backPath = UIBezierPath.init(arcCenter: CGPoint.init(x: self.p_centerX, y: self.p_centerY), radius: self.frame.size.width / 2.00, startAngle: CGFloat(-Double.pi * 7.0 / 6.0 ), endAngle: CGFloat(Double.pi / 6.0), clockwise: true)

        

        self.backGroundLayer.path = backPath.cgPath

        self.backGroundLayer.strokeStart = 0

        self.backGroundLayer.strokeEnd = 1

        self.backGroundLayer.strokeColor = backColor

        self.layer.addSublayer(self.backGroundLayer)

        

        

        self.backGroundLayer.fillColor = UIColor.clear.cgColor

        self.backGroundLayer.lineWidth = 1

 

 

//设置真实进度曲线

        self.progressLayer.frame = rect

        self.progressLayer.fillColor = UIColor.clear.cgColor

        self.progressLayer.lineWidth = 12

        self.progressLayer.lineCap = kCALineCapRound

        

        let progressPath = UIBezierPath.init(arcCenter: CGPoint.init(x: self.p_centerX, y: self.p_centerY), radius: self.frame.size.width / 2.00, startAngle: CGFloat(-Double.pi * 7.0 / 6.0 ), endAngle: CGFloat(endVale), clockwise: true)

        self.progressLayer.path = progressPath.cgPath

        self.progressLayer.strokeStart = 0

        self.progressLayer.strokeEnd = 1

        self.progressLayer.strokeColor = progressColor

        self.layer.addSublayer(self.progressLayer)

//添加动画

        let pathAnimation = CABasicAnimation.init(keyPath: "strokeEnd")

        pathAnimation.duration = 0.5

        pathAnimation.fromValue = 0

        pathAnimation.toValue = 1

        pathAnimation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseOut)

        self.progressLayer.add(pathAnimation, forKey: "strokeEnd")

    }

 

}

转载于:https://www.cnblogs.com/qizhuo/p/8665161.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值