CircleProgressButton 0.5.1

CircleProgressButton 0.5.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jan 2018
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Toshihiro Suzuki.



CircleProgressButton

UIView based circle button with CAShapeLayer based progress stroke.


platforms
Carthage compatible
Cocoapods
pod

Requirements

  • iOS9+
  • Swift4+

How to use

Customize Appearance

Colors and icon images are fully customizable. Either override or set preferred values.
Actually there's no default appearance, so have fun.👋

    open var defaultImage: UIImage?
    open var inProgressImage: UIImage?
    open var suspendedImage: UIImage?
    open var completedImage: UIImage?
    open var inProgressStrokeColor: UIColor?
    open var suspendedStrokeColor: UIColor?
    open var completedStrokeColor: UIColor?
    open var touchedAlpha: CGFloat = 0.5

UIImage's contentMode is .center. Make sure you provide correct size of image.

Update progress and state

  • state: updates color and icon image
  • progress: updates stroke progress
  • reset(): mutates both state and progress

It is possible to update progress while suspended.
state is read-only. Update via suspend(), resume(), complete() and reset().

Handle Tap

    private var token: CircleProgressButton.DisposeToken?

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        token = button.onTap { state in
             switch state {
             case .inProgress:
                print("suspend")
                self.stopJob()
             case .completed:
                print("delete")
                self.stopJob()
             case .default:
                print("start")
                self.resumeJob()
             case .suspended:
                print("resume")
                self.resumeJob()
             }
        }
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        token?.dispose()
    }

Using RxSwift

    override func viewDidLoad() {
        super.viewDidLoad()
        button.tapGesture.rx.event
            .subscribe(...)
            // ...
    }

For advanced touch interaction..

Feel free to assign your UIGestureRecognizerDelegate.

    button.tapGesture.delegate = self

License

MIT