amratab / FlexibleSteppedProgressBar

Flexible Stepped Progress Bar for IOS
Other
577 stars 113 forks source link

Progress bar disappears but the text remains #8

Closed vegidio closed 3 years ago

vegidio commented 7 years ago

Hi,

I created a progress bar with 4 points (progressBar.numberOfPoints = 4), but later I want to change this existing progress bar to 1 point (progressBar.numberOfPoints = 1).

The problem is, when I try to change to number of points from 4 to 1, the points disappear, but their texts remain. Following screenshots:

Initially, with 4 points:

4 steps

After progressBar.numberOfPoints = 1, with 1 point:

1 step

This is the code in my delegate:

    func progressBar(_ progressBar: FlexibleSteppedProgressBar, textAtIndex index: Int,
                     position: FlexibleSteppedProgressBarTextLocation) -> String {

        if position == FlexibleSteppedProgressBarTextLocation.bottom {
            switch index {
            case 0: return "BOOKED"
            case 1: return "ON THE WAY"
            case 2: return "SERVICING"
            case 3: return "COMPLETED"
            default: return "NONE"
            }
        }

        return ""
    }

How can I make the text under the points disappear as well when I go from 4 to 1 points?

amratab commented 7 years ago

Hi Vinícius, Let me try this myself and I will let you know the solution.

vegidio commented 7 years ago

I found a workaround for this problem.

Before I change the number of points from 4 to 1, I removed all CATextLayer objects from the view sublayers:

progressBar.layer.sublayers = progressBar.layer.sublayers?.filter {
    !$0.isKind(of: CATextLayer.self)
}
progressBar.numberOfPoints = 1
vegidio commented 7 years ago

Hi, is there any update on this? My workaround works, but it would be nice if the lib handled the removal of the sublayers when they are no longer needed, instead of making the developer handle them separately 🙂