暫無描述

IndicatorView.swift 1.5KB

    // // IndicatorView.swift // PaiAi-Guide // // Created by mac on 2016/12/13. // Copyright © 2016年 mac. All rights reserved. // import UIKit class IndicatorView: UIView { let color = UIColor(red: 55.0/255, green: 236.0/255, blue: 102.0/255, alpha: 1) var repeatCount: Float = 3 var lineColor = UIColor(red: 0, green: 165.0/255, blue: 0, alpha: 1) var lineWidth: CGFloat = 1.0 let anmiation = CABasicAnimation(keyPath: "transform.rotation.z") override func draw(_ rect: CGRect) { self.cornerRadius = self.frame.height / 2 let context = UIGraphicsGetCurrentContext() for i in 0..<181 { let shadowColor = color.withAlphaComponent(CGFloat(i) / 500.0).cgColor context?.setFillColor(shadowColor) context?.move(to: CGPoint(x: self.center.x, y: self.center.y)) context?.addArc(center: CGPoint(x: self.center.x, y: self.center.y), radius: self.frame.height / 2, startAngle: (-180 + CGFloat(i)) / 180 * .pi, endAngle: (-180 + CGFloat(i) - 1) / 180 * .pi, clockwise: true) context?.closePath() context?.drawPath(using: .fill) } context?.setStrokeColor(color.withAlphaComponent(0.9).cgColor) context?.move(to: CGPoint(x: self.center.x, y: self.center.y)) context?.addLine(to: CGPoint(x: self.frame.height, y: self.center.y)) context?.strokePath() anmiation.toValue = 2.0 * .pi anmiation.duration = 1 anmiation.repeatCount = repeatCount anmiation.isRemovedOnCompletion = false } }