Giter Site home page Giter Site logo

thepsguy / buttonprogressbar-ios Goto Github PK

View Code? Open in Web Editor NEW
574.0 14.0 48.0 1.26 MB

A small and flexible (well documented) UIButton subclass with animated loading progress, and completion animation.

Home Page: https://cocoapods.org/pods/ButtonProgressBar-iOS

License: MIT License

Ruby 9.89% Swift 90.11%
uibutton progress download animated loading subclass

buttonprogressbar-ios's Introduction

ButtonProgressBar-iOS

Version License Platform Contact

GIF Preview

Example

  • For LIVE PREVIEW on Appetize in your browser itself, click here.

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

Simulator Screen           GIF Preview

Requirements

iOS > 7.0

Installation

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

pod 'ButtonProgressBar-iOS'

Usage

import ButtonProgressBar_iOS

Initialize just like you would any other UIButton:

var progressButton = ButtonProgressBar(frame: CGRect)
view.addSubview(progressButton)

Since this is a UIButton subclass, targets and labels can be set in the same way:

progressButton.addTarget(nil, action: #selector(self.tapped), for: .touchUpInside)
progressButton.setTitle("Download", for: .normal)

The completion image can be set with;

This image must be set since no default exists.

  setCompletionImage(image: UIImage)

Indeterminate loading can be handled with the following functions:

startIndeterminate(withTimePeriod time: TimeInterval)
startIndeterminate(withTimePeriod time: TimeInterval, andTimePadding padding: TimeInterval)

/*
Time Padding is the duration (default 0.5), in seconds, before starting the next cycle.
Time Period is the total time (animation + padding) that 1 cycle of the loading takes.
*/

stopIndeterminate()  //Stops the indeterminate loading.

For determinate usage or otherwise, progress can be set with:

setProgress(progress: CGFloat, _ animated: Bool) 
/*
Progress ranges from 0.0 to 1.0

If animated is true, linearly animates to progress.
*/

resetProgress()  //Set progress to 0.0 unanimated.

Set the progress and background colors:

setBackgroundColor(color: UIColor)
setProgressColor(color: UIColor)

To explicitly show/hide the title / image:

hideTitle(_ hidden: Bool)
hideImage(_ hidden: Bool)

Stop indeterminate loading if active, set progress to 1.0 animated, and display completion image if set.

 Needs to be called explicitly when loading determinate as well.
  triggerCompletion()

Author

Pushkar Sharma, [email protected]


Inspiration from Dribbble

Android version available!

License

ButtonProgressBar-iOS is available under the MIT license. See the LICENSE file for more info.

buttonprogressbar-ios's People

Contributors

cs4alhaider avatar thepsguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

buttonprogressbar-ios's Issues

Swift 4 support?

Hi @thePsguy, thanks for the cool library. I am having an issue with the last released source.

I believe it's the right time to update it for the latest Swift?

Argument of '#selector' refers to instance method 'animateIndeterminate(sender:)' that is not exposed to Objective-C

screen shot 2018-02-08 at 10 39 55 am

Buggy animation

    func loadDeterminate() {
        self.progressButton.stopIndeterminate()
        self.progressButton.resetProgress()
        let timer = Timer.scheduledTimer(timeInterval: 1,
                                         target: self,
                                         selector: #selector(self.animateDeterminate),
                                         userInfo: time,
                                         repeats: true)
        RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
    }
    
    @objc func animateDeterminate(sender: Timer) {
        if self.progressButton.progress >= 1.0 {
            sender.invalidate()
        }
        else {
            self.progressButton.setProgress(progress: self.progressButton.progress + CGFloat(0.1), false)
        }
    }

I need to update the button rarely. So I replaced some numbers in your example, ran it on iphone 5s simulator, choose "determinate" and clicked this buttom:
1)timer's step is 0.1, its value is changed from 0 to 1. So why does it show 8 steps instead of 10?
2)if you do some clicks on button (or other clickable elements) - animation is changed unpredictably

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.