GithubHelp home page GithubHelp logo

urbanapps / uaprogressview Goto Github PK

View Code? Open in Web Editor NEW
1.0K 33.0 152.0 2.24 MB

UAProgressView is a simple and lightweight, yet powerful animated circular progress view

License: MIT License

Ruby 2.70% Objective-C 97.30%

uaprogressview's Introduction

UAProgressView is a simple and lightweight, yet powerful animated circular progress view.

UAProgressView

Installation

Installation is made simple with CocoaPods. If you want to do it the old fashioned way, just add UAProgressView.h and UAProgressView.m into your project.

pod 'UAProgressView'

Then, simply place this line in any file that uses UAProgressView.

#import <UAProgressView.h>

UAProgressView works on iOS 6.0 and up.

Usage

Simple Setup

UAProgressView has sensible defaults to make setup a breeze.

  1. Add a custom view to your storyboard, xib or create a UAProgressView in code.
  2. Set the progress on your UAProgressView by calling setProgress:

The progress should be a CGFloat between 0 and 1, but we will round to the closest if over/under.

The default color used for UAProgressView is the view's tintColor, and it will travel up the superview tree as expected to set it.

--

Custom Setup

There are many different configuration options to setup UAProgressView the way you want it.

Center View

Rather than force a stop button, label or some other canned central view, you can set the center view to be anything you want. In the example below, the centralView is set to a custom UILabel.

The centralView will be centered in the view but not resized, so plan accordingly when setting it up. It sits above the progress view in the layer hierarchy so it receives first tap.

There is no central view setup by default.

@property (nonatomic, strong) UIView *centralView;

Example usage:

UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60.0, 32.0)];
textLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:32];
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.textColor = self.progressView.tintColor;
textLabel.backgroundColor = [UIColor clearColor];
self.progressView.centralView = textLabel;
Border Width

Border width is the thickness of the outer circle. It is set to 1.0 by default.

@property (nonatomic, assign) CGFloat borderWidth;

Example usage:

self.progressView.borderWidth = 2.0;
Line Width

Line width is the thickness of the inner circle. It is set to 1.0 by default.

@property (nonatomic, assign) CGFloat lineWidth;

Example usage:

self.progressView.lineWidth = 2.0;
Selection Indication

When fillOnTouch is enabled (default is YES), UAProgressView will immediately fill the view with the tintColor. If the touch is then removed (ie: selected) the fill will fade out, similar to the iOS 7 phone app.

@property (nonatomic, assign) BOOL fillOnTouch;

Example usage:

self.progressView.fillOnTouch = YES;

Animation Duration

The duration over which to animate the progress set. Default is 0.3 seconds. animationDuration < 0 is ignored.

@property (nonatomic, assign) CFTimeInterval animationDuration;

The animationDuration variable is only used when calling setProgress:animated: with YES.

Long Press Gesture

This is the gesture that is created on the progress view to handle selection and (optionally) the long press. You can use this to customize the minimum duration required to invoke the selection gesture.

@property (nonatomic, strong) UILongPressGestureRecognizer *gestureRecognizer;

Long Press Duration

Specify an optional long press duration that will fire the didLongPressBlock when reached. Must be > 0.0. Default is 0.0 (disabled).

@property (nonatomic, assign) CGFloat longPressDuration;

Long Press Cancelling Selection

By default, the long press action will also trigger the selection action. You can disable this functionality with this property. Default is NO.

@property (nonatomic, assign) BOOL longPressCancelsSelect;

Event Blocks

On Select

You can set a block to be called when there was a touchUpInside on the progress view.

@property (nonatomic, copy) void (^didSelectBlock)(UAProgressView *progressView);

Example usage:

self.progressView.didSelectBlock = ^(UAProgressView *progressView){
    AudioServicesPlaySystemSound(_horn);
};
On Long Press

You can set a block to be called when there was an optional long press on the progress view. The long press is triggered when the longPressDuration is reached.

@property (nonatomic, copy) void (^didLongPressBlock)(UAProgressView *progressView);

Example usage:

self.progressView. didLongPressBlock = ^(UAProgressView *progressView){
    // Do something after long pressing the progress view
};
On Progress Change

You can set a block to be called whenever the progress is changed. This can be useful if the object updating the progress does not know about the central view.

@property (nonatomic, copy) void (^progressChangedBlock)(UAProgressView *progressView, CGFloat progress);

Example usage:

self.progressView.progressChangedBlock = ^(UAProgressView *progressView, CGFloat progress){
    [(UILabel *)progressView.centralView setText:[NSString stringWithFormat:@"%2.0f%%", progress * 100]];
};
On Fill Change

You can set a block to be called whenever the fill color is changed in your progress view. This is useful to invert colors on the central view, or do other visual updates when the progress view is filled.

@property (nonatomic, copy) void (^fillChangedBlock)(UAProgressView *progressView, BOOL filled, BOOL animated);

Example usage:

self.progressView.fillChangedBlock = ^(UAProgressView *progressView, BOOL filled, BOOL animated){
    UIColor *color = (filled ? [UIColor whiteColor] : progressView.tintColor);
    if (animated) {
        [UIView animateWithDuration:0.3 animations:^{
            [(UILabel *)progressView.centralView setTextColor:color];
        }];
    } else {
        [(UILabel *)progressView.centralView setTextColor:color];
    }
};

Configuration/Usage Examples

UAProgressView

For more information on how to use and setup UAProgressView, please see the example project.

UAProgressView vs. MRCircularProgressView

MRCircularProgressView is great and was the inspiration for UAProgressView, but it lacked much of the customization that UAProgressView now offers. UAProgressView is probably a better fit for you instead of MRProgress if you want:

  1. More customization
  2. More control
  3. No additional unused classes
  4. Block based interface

Bugs / Pull Requests

Let us know if you see ways to improve UAProgressView or see something wrong with it. We are happy to pull in pull requests that have clean code, and have features that are useful for most people.

What Does UA stand for?

Urban Apps. We make neat stuff. Check us out.

Open-Source Urban Apps Projects

  • Armchair - A simple yet powerful App Review Manager for iOS and OSX (Swift)
  • UAModalPanel - An animated modal panel alternative for iOS
  • UAAppReviewManager - An app review prompting tool for iOS and Mac App Store apps.
  • UALogger - A logging utility for Mac/iOS apps
  • UAObfuscatedString - A simple NSString category to hide sensitive strings
  • Urban - An Xcode color scheme that uses a soft dark background, with subtle blue, orange and yellow colors

Feeling Generous?

If you want to thank us for open-sourcing UAProgressView, you can buy one of our apps or even donate something small.

Click here to lend your support to: Support UAProgressView Development and make a donation at www.pledgie.com !

uaprogressview's People

Contributors

barbosa avatar coneybeare avatar jamierevans avatar joshuaseltzer avatar paulmars avatar readmecritic avatar tyrone-sudeium avatar ykws 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uaprogressview's Issues

I get an Apple Mach-O Linker Error

I'm trying to run your example from the xcodeproj file and I keep getting the following error:

ld: library not found for -lPods
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Change colors

Hi,

Is any way where we can change de color of progress to be different to the static circle. I mean, the possibility to modify both colours like we do with border and linewidth.

thanks

There is a warning.

  • (void)animateToProgress:(CGFloat)progress {

    ......

    animation.delegate = self; ( Assigning to 'id _Nullable' from incompatible type 'UAProgressView *const __strong')

    ......
    }

Progress is flashing when setprogress:animated:YES

Hey sir!
Thanks for great class!
The problem is when I`m setting progress animated it goes great but when animation is finished the progressview is flashing (from last progress to current)
I think its in updating BezierPath

Can u help me pls?

TY
Grigory

Example: pod install Error and Warning

Example pod install has error and warning.

Error

[!] Could not automatically select an Xcode workspace. Specify one in your Podfile like so:

    workspace 'path/to/Workspace.xcworkspace'

Warning

[!] The abstract target Pods is not inherited by a concrete target, so the following dependencies won't make it into any targets in your project:
    - UAProgressView (from `..`)
All log

% pod install
Re-creating CocoaPods due to major version update.
Analyzing dependencies
Downloading dependencies
Installing UAProgressView (0.1.4)
Generating Pods project
Integrating client projects
[!] Could not automatically select an Xcode workspace. Specify one in your Podfile like so:
workspace 'path/to/Workspace.xcworkspace'

[!] The abstract target Pods is not inherited by a concrete target, so the following dependencies won't make it into any targets in your project:
- UAProgressView (from ..)

Alias

pod: aliased to arch -x86_64 pod

Spec

- M1 Mac
- ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin20]
- CocoaPods 1.11.2
- Xcode 13.2.1

Tap and Hold Gesture (Long Press)

Would it be possible to expose a "tap and hold" gesture on this view? I would like to perform some actions when the touches are held for a specified amount of seconds.

[Swift] value of central labelview not updated in progressChangedBlock

Nice project!

I am integrating UAProgressView in my project written in swift. I tried to update the value of the current progress as follows:

override func awakeFromNib() {
    super.awakeFromNib()
    self.progressView.borderWidth = 2.0
    self.progressView.lineWidth = 8.0
    self.progressView.fillOnTouch = false
    self.progressView.animationDuration = 2.0

    self.textLabel = UILabel(frame: CGRectMake(0, 0, 60.0, 32.0))
    self.textLabel.font = UIFont(name: "HelveticaNeue-UltraLight", size: 22)
    self.textLabel.textAlignment = NSTextAlignment.Center
    self.textLabel.textColor = self.progressView.tintColor
    self.textLabel.backgroundColor = UIColor.clearColor()
    self.progressView.centralView = self.textLabel



    self.progressView.progressChangedBlock = { (progressView:UAProgressView!,  progress:Float) -> () in
        let lableview = progressView.centralView as! UILabel
        lableview.text = StringManager.float2str(progress*100)
        println("Current progress")
        println(progress)
    }  
} 

But the block is invoked only once as in the main code:

self.scoreshareview.setViewProgress(StringManager.str2float(score))

function setViewProgress:

func setViewProgress(score:Float){
    self.progressView.setProgress(score/100, animated: true)
}

I am new to iOS and not sure where the problem is.

Thanks for sharing!

Please release a new version.

I've been using the HEAD parameter in my Podfile for getting the fix in e887eea for months to avoid flashing in setProgress:animated.

The last version was released on Jul 19. Please release a new version to include these fixes after Jul 19. Thanks.

Compute progress using AVAudioRecorder currentTime property

How do we compute for the progress if we're gonna use AVAudioRecorder current time?

I'm after a 15 seconds recording time. Right now my code below is not allowing me to achieve this.

This is what I have now:

-(void)recording{
[self.progress setAnimationDuration:15.0];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.05
                                                  target:self
                                                selector:@selector(updateProgress)
                                                userInfo:nil
                                                 repeats:YES];
}

- (void)updateProgress{
    [self.progress setProgress:self.audioRecorder.currentTime];
}

Intermediate state is missing like MRCircularProgressView

Hello,

I am trying to use this component as its more flexible than other referred as per my requirement.

Is there a possible to have an intermediate rotating circle while the transfer is yet to be started to download / upload.

How to change the borderColor ?

Hi , I want to change the bordercolor to whiteColor ,but it dosent work , and still show with tintcolor ! How can I solve it?

Can't run example

$ pod install
Analyzing dependencies
Fetching podspec for `UAProgressView` from `..`
[!] Unable to satisfy the following requirements:

- `UAProgressView (from `..`)` required by `Podfile`

tintColor和fillColor

fillColor设置无效。
如何让填充的圆环和背景圆环重叠在一起?

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.