Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thumb at the end of progress line #67

Open
shivang2902 opened this issue Feb 24, 2017 · 3 comments
Open

Add thumb at the end of progress line #67

shivang2902 opened this issue Feb 24, 2017 · 3 comments

Comments

@shivang2902
Copy link

First of all thanks for the wonderful lib, is there any support for the thumb at the end of the progress line

Thanks

@shivang2902
Copy link
Author

shivang2902 commented Mar 1, 2017

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)
       ......................

`

screen shot 2017-03-01 at 12 06 16 pm

@shivang2902
Copy link
Author

Can you please help me on this

Thanks in advance !! :)

@vinayak-nickelfox
Copy link

Has anyone found how to implement thumb on progress bar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants