KDCircularProgress
KDCircularProgress copied to clipboard
Add thumb at the end of progress line
First of all thanks for the wonderful lib, is there any support for the thumb at the end of the progress line
Thanks
For now i am trying this code, it is add the thumb but at wrong place ` func rect(forDegree degree: Float, andRect rect: CGRect) -> CGRect {
var x: Float = self.xPosRound(forAngle: degree, andRect: rect) - 6.9
var y: Float = self.yPosRound(forAngle: degree, andRect: rect) - 6.9
return CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(6.9), height: CGFloat(6.9))
}
func yPosRound(forAngle degree: Float, andRect rect: CGRect) -> Float {
let arcRadius = getArcRadius()
return cosf(degree.degreesToRadians) * Float(arcRadius) - cosf(degree.degreesToRadians) + Float(rect.size.width / 2)
}
func xPosRound(forAngle degree: Float, andRect rect: CGRect) -> Float {
let arcRadius = getArcRadius()
return sinf(degree.degreesToRadians) * Float(arcRadius) - sinf(degree.degreesToRadians) + Float(rect.size.width / 2)
}
func getArcRadius() -> CGFloat {
let trackLineWidth = radius * trackThickness
let progressLineWidth = radius * progressThickness
let arcRadius = max(radius - trackLineWidth/2, radius - progressLineWidth/2)
return arcRadius
}
override func draw(in ctx: CGContext) {
UIGraphicsPushContext(ctx)
let size = bounds.size
let width = size.width
let height = size.height
let arcRadius = getArcRadius()
ctx.addArc(center: CGPoint(x: width/2.0, y: height/2.0), radius: arcRadius, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: false)
trackColor.set()
ctx.setStrokeColor(trackColor.cgColor)
ctx.setFillColor(progressInsideFillColor.cgColor)
ctx.setLineWidth(trackLineWidth)
ctx.setLineCap(CGLineCap.butt)
ctx.drawPath(using: .fillStroke)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
let imageCtx = UIGraphicsGetCurrentContext()
let reducedAngle = Utility.mod(value: angle, range: 360, minMax: (0, 360))
let fromAngle = Conversion.degreesToRadians(value: CGFloat(-startAngle))
let toAngle = Conversion.degreesToRadians(value: CGFloat((clockwise == true ? -reducedAngle : reducedAngle) - startAngle))
imageCtx?.addArc(center: CGPoint(x: width/2.0, y: height/2.0), radius: arcRadius, startAngle: fromAngle, endAngle: toAngle, clockwise: clockwise)
let rectangle = self.rect(forDegree: Float(self.angle), andRect: self.bounds)
imageCtx?.addEllipse(in: rectangle)
let glowValue = GlowConstants.glowAmount(forAngle: reducedAngle, glowAmount: glowAmount, glowMode: glowMode, size: width)
......................
`
Can you please help me on this
Thanks in advance !! :)
Has anyone found how to implement thumb on progress bar?