Latest 0.5.1
Homepage https://github.com/toshi0383/CircleProgressButton
License MIT
Platforms ios 9.0
Authors

CircleProgressButton

UIView based circle button with CAShapeLayer based progress stroke.

CircleProgressButton
CircleProgressButton
CircleProgressButton
CircleProgressButton

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 strokeMode: StrokeMode = .fill
    open var touchedAlpha: CGFloat = 0.5
    public var animated: Bool = true

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
  • complete(): mutates both state and progress

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

Disable/Enable Animations

By default implicit CALayer’s animations are enabled.
You can disable or enable this behavior either by

  • mutating animationEnableOptions property
  • Use CircleProgressButton#animate(animationEnableOption:_:) or CircleProgressButton#performWithoutAnimation(animationEnableOption:_:)

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.suspendJob()
             case .completed:
                print("delete")
                self.cancelJob()
             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

Latest podspec

{
    "name": "CircleProgressButton",
    "version": "0.5.1",
    "summary": "UIView based circle button with CAShapeLayer based progress stroke",
    "description": "'UIView based circle button with CAShapeLayer based progress stroke.'",
    "homepage": "https://github.com/toshi0383/CircleProgressButton",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "toshi0383": "[email protected]"
    },
    "source": {
        "git": "https://github.com/toshi0383/CircleProgressButton.git",
        "tag": "0.5.1"
    },
    "social_media_url": "https://twitter.com/toshi0383",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "CircleProgressButton/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This