amratab / FlexibleSteppedProgressBar

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

Text Overflowing #25

Closed amhinson closed 4 years ago

amhinson commented 5 years ago

I can't seem to figure out why the label text is too large and overflowing into the next item. Any ideas?

image 2019-02-06 at 6 46 07 am
 var progressBar: FlexibleSteppedProgressBar!
    var progressBarWithoutLastState: FlexibleSteppedProgressBar!
    var progressBarWithDifferentDimensions: FlexibleSteppedProgressBar!

    var backgroundColors = UIColor(red: 112.0 / 255.0, green: 160.0 / 255.0, blue: 71.0 / 255.0, alpha: 1.0)
    var progressColor = UIColor(red: 112.0 / 255.0, green: 160.0 / 255.0, blue: 71.0 / 255.0, alpha: 1.0)
    var textColorHere = UIColor(red: 153.0 / 255.0, green: 153.0 / 255.0, blue: 153.0 / 255.0, alpha: 1.0)

    var maxIndex = -1

override func setSelected(_ selected: Bool, animated: Bool){
        super.setSelected(selected, animated: animated)
    }

    func setupProgressBar(selected: Int) {
        progressBar = FlexibleSteppedProgressBar()
        progressBar.translatesAutoresizingMaskIntoConstraints = false
        for view in self.subviews {
            if let progress = view as? FlexibleSteppedProgressBar {
                progress.removeFromSuperview()
            }
        }
        self.addSubview(progressBar)

        // iOS9+ auto layout code
        let horizontalConstraint = progressBar.centerXAnchor.constraint(equalTo: self.centerXAnchor)
        let verticalConstraint = progressBar.topAnchor.constraint(
            equalTo: self.topAnchor,
            constant: 80
        )
        let widthConstraint = progressBar.widthAnchor.constraint(equalToConstant: SCREEN_WIDTH - 36)
        let heightConstraint = progressBar.heightAnchor.constraint(equalToConstant: CGFloat(64))
        NSLayoutConstraint.activate([horizontalConstraint, verticalConstraint, widthConstraint, heightConstraint])

        // Customise the progress bar here
        progressBar.numberOfPoints = 6
        progressBar.lineHeight = 2
        progressBar.radius = 5
        progressBar.progressRadius = 6
        progressBar.progressLineHeight = 2
        progressBar.delegate = self
        progressBar.completedTillIndex = selected
        progressBar.useLastState = true
        progressBar.lastStateCenterColor = progressColor
        progressBar.selectedBackgoundColor = progressColor
        progressBar.selectedOuterCircleStrokeColor = progressColor
        progressBar.lastStateOuterCircleStrokeColor = progressColor
        progressBar.currentSelectedCenterColor = progressColor
        progressBar.currentSelectedTextColor = progressColor
        progressBar.currentIndex = 0
    }

    func progressBar(_ progressBar: FlexibleSteppedProgressBar,
                     didSelectItemAtIndex index: Int) {
        progressBar.currentIndex = index
        if index > maxIndex {
            maxIndex = index
            progressBar.completedTillIndex = maxIndex
        }
    }

    func progressBar(_ progressBar: FlexibleSteppedProgressBar,
                     canSelectItemAtIndex index: Int) -> Bool {
        return false
    }

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

        if progressBar == self.progressBar || progressBar == self.progressBarWithoutLastState {
            if position == FlexibleSteppedProgressBarTextLocation.top {
                switch index {

                case 0: return "Quote Pending"
                case 1: return "Quote Approved"
                case 2: return " Route "
                case 3: return "Getting Swerviced"
                case 4: return "Swervice Complete"
                case 5: return "Delivery Complete"
                default: return "Nothing"
                }
            }
        }
        return ""
    }