let radius = self.headImageView.frame.width/2 + 3 //半径
let arcCenter = self.headImageView.center//圆心
//通过贝塞尔曲线画出圆弧,参数分别为圆心、半径、开始弧度、结束弧度、顺/逆时针
self.arcLayer.path = UIBezierPath(arcCenter: arcCenter, radius: radius, startAngle: conversionRadian(90), endAngle: conversionRadian(360*complete+90), clockwise: true).CGPath
self.arcLayer.fillColor = UIColor.clearColor().CGColor//填充色
self.arcLayer.strokeColor = UIColor.redColor().CGColor//画笔色
self.arcLayer.lineWidth = 6//线宽度
self.arcLayer.lineDashPattern = [2,1]//设置虚线样式,数组
let drawAnimation = CABasicAnimation(keyPath: "strokeEnd")
drawAnimation.duration = 0.5;
drawAnimation.repeatCount = 1.0;
drawAnimation.removedOnCompletion = false;
drawAnimation.fromValue = 0
drawAnimation.toValue = 1
drawAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
self.arcLayer.addAnimation(drawAnimation, forKey: "strokeEnd")
//创建渐变图层
self.gradientLayer.frame = CGRect(x: 0, y: 0, width: self.headImageBgView.frame.width, height: self.headImageBgView.frame.height)
self.gradientLayer.colors = [UIColor(hexString: "#FFDD74", alpha: 1)!.CGColor,UIColor(hexString: "#FF6000", alpha: 1)!.CGColor]
self.gradientLayer.startPoint = CGPoint(x: 0, y: 0)//开始左上角
self.gradientLayer.endPoint = CGPoint(x: 1, y: 1)//结束点右下角
self.gradientLayer.mask = self.arcLayer
self.headImageBgView.layer.addSublayer(self.gradientLayer)