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)
iOS - 虚线圆弧
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 使用cocopods时遇到以下错误: CocoaPods did not set the base configu...