Flexible Stepped Progress Bar for IOS

Overview

FlexibleSteppedProgressBar

CI Status Swift Version License Platform

This is a stepped progress bar for IOS. The base code is derived from ABSteppedProgressBar. Most of the design is customisable. Text can be positioned inside the circles or on top or bottom of them or if the user wants, at all the three places. Please refer to usage section for more details.

alt tag alt tag

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

FlexibleSteppedProgressBar is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "FlexibleSteppedProgressBar"

Basic Usage

import FlexibleSteppedProgressBar

class ViewController: UIViewController, FlexibleSteppedProgressBarDelegate {

    var progressBar: FlexibleSteppedProgressBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        progressBar = FlexibleSteppedProgressBar()
        progressBar.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(progressBar)

        let horizontalConstraint = progressBar.centerXAnchor.constraintEqualToAnchor(self.view.centerXAnchor)
        let verticalConstraint = progressBar.topAnchor.constraintEqualToAnchor(
            view.topAnchor,
            constant: 80
        )
        let widthConstraint = progressBar.widthAnchor.constraintEqualToAnchor(nil, constant: 500)
        let heightConstraint = progressBar.heightAnchor.constraintEqualToAnchor(nil, constant: 150)
        NSLayoutConstraint.activateConstraints([horizontalConstraint, verticalConstraint, widthConstraint, heightConstraint])

        // Customise the progress bar here
        progressBar.numberOfPoints = 5
        progressBar.lineHeight = 9
        progressBar.radius = 15
        progressBar.progressRadius = 25
        progressBar.progressLineHeight = 3
        progressBar.delegate = self
    }
    
    func progressBar(progressBar: FlexibleSteppedProgressBar,
                 didSelectItemAtIndex index: Int) {
        print("Index selected!")
    }
    
    func progressBar(progressBar: FlexibleSteppedProgressBar,
                 willSelectItemAtIndex index: Int) {
        print("Index selected!")
    }

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

    func progressBar(progressBar: FlexibleSteppedProgressBar,
                     textAtIndex index: Int, position: FlexibleSteppedProgressBarTextLocation) -> String {
        if position == FlexibleSteppedProgressBarTextLocation.BOTTOM {
            switch index {
                
            case 0: return "First"
            case 1: return "Second"
            case 2: return "Third"
            case 3: return "Fourth"
            case 4: return "Fifth"
            default: return "Date"
                
            }
        }
    return ""
    }
}

Customisations

I made some modifications upon ABSteppedProgressBar because I had an extra state to cater to, Last State. It specifies the last indice user has covered on the progress bar. For example, my use case was to specify properties of a product in a particular oder through progress bar lets say there were Step 1, Step 2 to Step 5. So, if the user has completed till step 3, and he goes back to step 1 to make some modification, progres bar should indicate separately the step 3 as last state and step 1 as selected state. It is completely optional here. If you want to use last state, you can simply state your wish through useLastState parameter and specify completedTillIndex as the last state. Progress bar does not keep track of the last state.

There are four states for a progress point:
1. Unselected and unvisited
2. Unselected and visited
3. Currently selected: These will have two concentric circles whose colors can be specified through 
    a) currentSelectedCenterColor: for inner circle fill color
    b) selectedOuterCircleStrokeColor: outer circle stroke color
    c) selectedOuterCircleLineWidth: outer circle line width
4. Last state: Use of this state is up on the discretion of the implementation. It is by default false and can be changed through useLastState. If present, it will also have two concentric circles whose colors can be modified through:
    a) lastStateCenterColor: for inner circle fill color
    b) lastStateOuterCircleStrokeColor: for outer circle stroke color
    c) lastStateOuterCircleLineWidth: for outer circle line width

Some general customisation options: 
a) radius: Radius of circles for unvisited indices.
b) progressRadius: Radius of circles for visited indices.
c) lineHeight: Line height of the outer line for complete progress bar.
d) progressLineHeight: Line height for the inner line with the selected background color that is shown only for the visited indices.
e) numberOfPoints: It is the number of indices on the progress bar.
f) stepAnimationDuration: Duration of animation
g) backgroundShapeColor: This is the color for unselected and unvisited indices.
h) selectedBackgoundColor: This is the color for unselected but visited indices.
i) currentIndex: It is the current selected index. Value: 0 to (number of points - 1)
j) completedTillIndex: It is the last state index. Value: 0 to (number of points - 1)

CAUTION: If your background view is of any other color than white, please specify it in viewBackgroundColor. Otherwise you will keep seeing white color in between.

Second reason for this library was text location. I needed flexible position for text. So, here I am providing three locations. 
a) TOP
b) CENTER
c) BOTTOM

You can specify the text you want to show through delegate method textAtIndex. For customising how text is displayed, specify the following values:
a) currentSelectedTextColor: This is the text color for the current selected index for top and bottom positions.
b) centerLayerTextColor: This is the text color for the the indices when it is neither selected nor last state only for center position.
c) centerLayerDarkBackgroundTextColor: This is the text color for center position when it is either selected or last state.
d) stepTextColor: This is the text color in the top or bottom positions for all but selected indices.
e) stepTextFont: This is the font for all the positions and indices.
f) textDistance: This is the distance of top and bottom text from the center of their respective indices. 

Also, other customisation options are available through delegate methods.

Author

Amrata Baghel, [email protected]

License

FlexibleSteppedProgressBar is available under the MIT license. See the LICENSE file for more info.

Comments
  • Step text into 2 lines???

    Step text into 2 lines???

    I set the text to "Order\ndelivered" with a "\n" newline in between. but it only shows "Order" not "delivered" on the second line. Can you support that??

    opened by stvding 11
  • Progress bar disappears but the text remains

    Progress bar disappears but the text remains

    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?

    opened by vegidio 3
  • didSelectItemAtIndex() delegate not fired after setting current index

    didSelectItemAtIndex() delegate not fired after setting current index

    Hi, for first, good job !

    I just see that didSelectItemAtIndex() delegate method is not fired after setting current index, just need to call in setter

    
    FlexibleSteppedProgressBar.swift
    
    /// The current selected index
        open var currentIndex: Int = 0 {
            willSet(newValue){
                if let delegate = self.delegate {
                    delegate.progressBar?(self, willSelectItemAtIndex: newValue)
                }
            }
            didSet {
    //            animationRendering = true
                self.setNeedsDisplay()
                if let delegate = self.delegate {
                    delegate.progressBar?(self, didSelectItemAtIndex: currentIndex)
                }
            }
        }
    
    
    opened by aliasdoc 3
  • Added RTL support for the Progress bar and inside, top and bottom text labels

    Added RTL support for the Progress bar and inside, top and bottom text labels

    Added an attribute (isRTL) to allow support for Right to Left languages. Upon setting it to true:

    • ProgressBar view gets transformed (flipped horizontally).
    • Top, Bottom, and inside circle labels get transformed (double flipped), so they can be read normally.

    Tested it in a multi-language app I am working on.

    opened by abdulla-allaith 2
  •  Convert to Swift4.2 syntax & Xcode10 project.

    Convert to Swift4.2 syntax & Xcode10 project.

    I found this master branch is behind in the latest version. So I convert Swift4.2 syntax & adopt to Xcode10 or above.

    Examples:

    • UIApplicationLaunchOptionsKeyUIApplication.LaunchOptionsKey
    • UIViewContentMode.redrawUIView.ContentMode.redraw
    • NSAttributedStringKeyNSAttributedString.Key
    • kCAMediaTimingFunctionEaseInEaseOutAMediaTimingFunctionName.easeInEaseOut
    • UIGestureRecognizerState.endedUIGestureRecognizer.State.ended

    Thanks.

    opened by fumiyasac 2
  • Set stepText indices font?

    Set stepText indices font?

    Is it possible to set a font for the indices only? I don't set a font at all and get this Warning ->

    CoreText performance note: Client called CTFontCreateWithName() using name ".SFUI-Semibold" and got font with PostScript name "TimesNewRomanPSMT". For best performance, only use PostScript names when calling this API.

    opened by domfz 1
  • Could not build Objective-c Module 'FlexibleSteppedProgressBar'

    Could not build Objective-c Module 'FlexibleSteppedProgressBar'

    I already done pod install but when I try to import FlexibleSteppedProgressBar it gives me error Could not build Objective-c Module 'FlexibleSteppedProgressBar'.

    opened by SaurabhForcebolt 1
  • Hide top and bottom label

    Hide top and bottom label

    Hii, I'm working on a project where only need FlexibleSteppedProgressBar but not label which is shown at top and bottom. can you suggest how to customize it?

    I need something like below one img_0638

    opened by prakashtripathi 1
  • Font issue fixed for centre text.

    Font issue fixed for centre text.

    I tried to change font of the centre text by assigning new custom font to the property "stepTextFont". But this property was only changing the top and bottom fonts. So i tried to change those lines and it worked. If the changes seems fare, please merge with main code.

    opened by mahesh-agrawal-616 1
  • Titles from both the end are clipping

    Titles from both the end are clipping

    I am using this library and I am getting this issue. Titles from both the end are getting clipped. This is happening in all the screens width and for number of points. Here is the screenshot for the same. simulator screen shot - iphone 8 plus - 2018-05-18 at 18 20 47

    opened by RajanLogicalWings 1
  • arbitrary segment lengths?

    arbitrary segment lengths?

    Just wondering if this library supports arbitrary segmetn lengths? for example i want from segment 1 (point 0 to point 1) to be 100 px, but i want the second segment (point 1 to point 2) to be 400 px. I guess I could just use 2 separate instances now that im thinking about it.

    opened by nick-iCars 1
  • Example Designed only for iPad, Update example for iPhone

    Example Designed only for iPad, Update example for iPhone

    Example is designed for only iPad, not for iPhone. Kindly update the example for iPhone too, for both portrait and landscape. Also add it in scroll view for smaller screen. IMG_5999 IMG_5998

    opened by asifhabib 0
  • the progress bar doesn't support RTL

    the progress bar doesn't support RTL

    Hi I have an app which support 2 language (arabic, English) LTR & RTL so in arabic I need it start form Right to left side

    I tried to perform "transform" but it Mirrors the whole view with all its content and I can't control the labels because its text layers , could you provide me with a solution

    thanks a lot for this

    opened by ghass64 2
  • change label text color of previous and next indicator

    change label text color of previous and next indicator

    I want to make it same color of selected to previous same and next all should be same. For example: I have 4 progress and if i am at second index, than first and second label text color want same and other text color want different.

    second example : If i am at 3rd index, so first/second/third index color want same and forth index color want different. if i will click on previous from 3rd index , means now i am at second, so first/second color want same other want different.

    Let me know how to achieve this ? Please refer attached screenshot.

    Screenshot 2020-04-21 at 3 23 46 PM

    opened by tusharMistri 1
  • Not able to get progress bar where selected steps has white color text and remaining step has gray color text

    Not able to get progress bar where selected steps has white color text and remaining step has gray color text

    I want stepper like this one Screenshot 2020-03-18 at 9 17 12 AM

    And I have written below code:

    func setupProgressBarWithDifferentDimensions() {
            progressBarWithDifferentDimensions = FlexibleSteppedProgressBar()
            progressBarWithDifferentDimensions.translatesAutoresizingMaskIntoConstraints = false
            self.view.addSubview(progressBarWithDifferentDimensions)
            
            // iOS9+ auto layout code
            let horizontalConstraint = progressBarWithDifferentDimensions.centerXAnchor.constraint(equalTo: self.view.centerXAnchor)
            let verticalConstraint = progressBarWithDifferentDimensions.topAnchor.constraint(
                equalTo: view.topAnchor,
                constant: 450
            )
            let widthConstraint = progressBarWithDifferentDimensions.widthAnchor.constraint(equalToConstant: 320)
            let heightConstraint = progressBarWithDifferentDimensions.heightAnchor.constraint(equalToConstant: 25)
            NSLayoutConstraint.activate([horizontalConstraint, verticalConstraint, widthConstraint, heightConstraint])
                    
            progressBarWithDifferentDimensions.numberOfPoints = 5
            progressBarWithDifferentDimensions.lineHeight = 5
            progressBarWithDifferentDimensions.progressLineHeight = 6
            progressBarWithDifferentDimensions.radius = 16
            progressBarWithDifferentDimensions.progressRadius = 16
            progressBarWithDifferentDimensions.delegate = self
            progressBarWithDifferentDimensions.selectedBackgoundColor = progressColor
            progressBarWithDifferentDimensions.backgroundShapeColor = UIColor.lightGray
    //        progressBarWithDifferentDimensions.centerLayerDarkBackgroundTextColor = UIColor.green
    //        progressBarWithDifferentDimensions.centerLayerTextFont = UIFont.systemFont(ofSize: 17)
            progressBarWithDifferentDimensions.selectedOuterCircleLineWidth = 0.0
            
            progressBarWithDifferentDimensions.completedTillIndex = 2
            progressBarWithDifferentDimensions.currentIndex = 2
            
            progressBarWithDifferentDimensions.stepTextColor = UIColor.yellow
            progressBarWithDifferentDimensions.currentSelectedTextColor = UIColor.white
            progressBarWithDifferentDimensions.centerLayerTextColor = UIColor.gray
        }
    
    opened by dhaval-dobariya 0
Owner
Amrata Baghel
Backend engineer, iOS(Swift) and android app developer.
Amrata Baghel
UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics

The YLProgressBar is an UIProgressView replacement with a highly and fully customizable animated progress bar in pure Core Graphics. It has been imple

Yannick Loriot 1.3k Jan 5, 2023
A simple animated progress bar in Swift

DSGradientProgressView Introduction DSGradientProgressView is a simple and customizable animated progress bar written in Swift. Inspired by GradientPr

Dhol Studio 445 Oct 13, 2022
📊 A customizable gradient progress bar (UIProgressView).

GradientProgressBar A customizable gradient progress bar (UIProgressView). Inspired by iOS 7 Progress Bar from Codepen. Example To run the example pro

Felix M. 490 Dec 16, 2022
Simple and powerful animated progress bar with dots

Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8.0+ Swift 3.0+ Installatio

Nikola Corlija 42 Dec 5, 2022
💈 Retro looking progress bar straight from the 90s

Description Do you miss the 90s? We know you do. Dial-up internet, flickering screens, brightly colored websites and, of course, this annoyingly slow

HyperRedink 18 Nov 24, 2022
Completely customizable progress based loaders drawn using custom CGPaths written in Swift

FillableLoaders Completely customizable progress based loaders drawn using custom CGPaths written in Swift Waves Plain Spike Rounded Demo: Changelog:

Pol Quintana 2.1k Dec 31, 2022
Step-by-step progress view with labels and shapes. A good replacement for UIActivityIndicatorView and UIProgressView.

StepProgressView Step-by-step progress view with labels and shapes. A good replacement for UIActivityIndicatorView and UIProgressView. Usage let progr

Yonat Sharon 340 Dec 16, 2022
Simple Swift Progress HUD

MKProgress An iOS Simple Swift Progress HUD Requirements iOS 9.0+ Swift 3.0+ Xcode 8.0+ Installation MKProgress is only available via CocoaPods: pod '

Muhammad Kamran 143 Dec 23, 2022
A clean and lightweight progress HUD based on SVProgressHUD, converted to Swift with the help of Swiftify.

IHProgressHUD IHProgressHUD is a clean and easy-to-use HUD meant to display the progress of an ongoing task on iOS and tvOS. IHProgressHUD is based on

Swiftify 202 Dec 22, 2022
⌛️A customizable animated gradient loading bar.

GradientLoadingBar A customizable animated gradient loading bar. Inspired by iOS 7 Progress Bar from Codepen. Example To run the example project, clon

Felix M. 791 Dec 26, 2022
StatusBarOverlay will automatically show a "No Internet Connection" bar when your app loses connection, and hide it again

StatusBarOverlay will automatically show a "No Internet Connection" bar when your app loses connection, and hide it again. It supports apps which hide the status bar and The Notch

Idle Hands Apps 160 Nov 2, 2022
A beautiful activity indicator and modal alert written in Swift (originally developed for my app DoodleDoodle) Using blur effects, translucency, flat and bold design - all iOS 8 latest and greatest

SwiftSpinner SwiftSpinner is an extra beautiful activity indicator with plain and bold style. It uses dynamic blur and translucency to overlay the cur

Marin Todorov 2.1k Dec 19, 2022
The easiest way to handle a simple full screen activity indicator in iOS. Written in Swift.

LLSpinner An easy way to handle full screen activity indicator. Easy to use Get Started // Show spinner LLSpinner.spin() // Hide spinner LLSpinner.st

Aleph Retamal 36 Dec 9, 2021
A view class for iOS that makes uploading easy and beautiful.

SVUploader A view class for iOS that makes uploading easy and beautiful. Demo SVUploader is fully customizable - check out 2 demos. Installation Just

Kiran 79 Apr 18, 2022
A lightweight and awesome loading Activity Indicator for your iOS app.

BPCircleActivityIndicator BPCircleActivityIndicator is a clean and easy-to-use Activity Indicator meant to display the progress of an ongoing task on

Ben.Park 46 Aug 12, 2022
A simple and awesome loading Activity Indicator(with block moving animation) for your iOS app.

BPBlockActivityIndicator BPBlockActivityIndicator is a clean and easy-to-use Activity Indicator meant to display the progress of an ongoing task on iO

Ben.Park 43 Nov 6, 2021
IOS HUD Swift Library

JHProgressHUD JHProgressHUD is an iOS class written in Swift to display a translucent HUD with an indicator and/or labels while work is being done in

Harikrishnan T 79 Feb 27, 2021
Stepped ProgressBar for iOS

JKSteppedProgressBar Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements To use JKS

Johnykutty Mathew 130 Aug 1, 2022
UIView based progress bar that shows a progress based on duration in seconds

DurationProgressBar Create a progress bar based on a duration in seconds. The view is fully customisable. Install Add this repository to your swift pa

Cem Olcay 2 May 21, 2022
Shawn Frank 2 Aug 31, 2022