Giter Club home page Giter Club logo

ylprogressbar's Introduction

YLProgressBar

Supported Platforms Version

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

YLProgressBar

It has been implemented using the Core Graphics framework without any images. So it can be customized freely and independently on the platform.

UsageInstallationContributionContactLicense

Usage

Here are some examples to show you how the YLProgressBar can be configured:

// Blue flat progress, with no stripes
_progressBar.type               = YLProgressBarTypeFlat;
_progressBar.progressTintColor  = [UIColor blueColor];
_progressBar.hideStripes        = YES;

// Green rounded/gloss progress, with vertical animated stripes in the left direction
_progressBar.type               = YLProgressBarTypeRounded;
_progressBar.progressTintColor  = [UIColor greenColor];
_progressBar.stripesOrientation = YLProgressBarStripesOrientationVertical;
_progressBar.stripesDirection   = YLProgressBarStripesDirectionLeft;

// Rainbow flat progress, with the indicator text displayed over the progress bar
NSArray *rainbowColors = @[[UIColor colorWithRed:33/255.0f green:180/255.0f blue:162/255.0f alpha:1.0f],
                           [UIColor colorWithRed:3/255.0f green:137/255.0f blue:166/255.0f alpha:1.0f],
                           [UIColor colorWithRed:91/255.0f green:63/255.0f blue:150/255.0f alpha:1.0f],
                           [UIColor colorWithRed:87/255.0f green:26/255.0f blue:70/255.0f alpha:1.0f],
                           [UIColor colorWithRed:126/255.0f green:26/255.0f blue:36/255.0f alpha:1.0f],
                           [UIColor colorWithRed:149/255.0f green:37/255.0f blue:36/255.0f alpha:1.0f],
                           [UIColor colorWithRed:228/255.0f green:69/255.0f blue:39/255.0f alpha:1.0f],
                           [UIColor colorWithRed:245/255.0f green:166/255.0f blue:35/255.0f alpha:1.0f],
                           [UIColor colorWithRed:165/255.0f green:202/255.0f blue:60/255.0f alpha:1.0f],
                           [UIColor colorWithRed:202/255.0f green:217/255.0f blue:54/255.0f alpha:1.0f],
                           [UIColor colorWithRed:111/255.0f green:188/255.0f blue:84/255.0f alpha:1.0f]];

_progressBar.type                     = YLProgressBarTypeFlat;
_progressBar.hideStripes              = YES;
_progressBar.indicatorTextDisplayMode = YLProgressBarIndicatorTextDisplayModeProgress;
_progressBar.progressTintColors       = rainbowColors;

// To allow the gradient colors to fit the progress width
_progressBar.progressStretch          = YES;

You can also use the UIAppearence protocol to configure all the progress bars at once:

[[YLProgressBar appearance] setType:YLProgressBarTypeFlat];
[[YLProgressBar appearance] setProgressTintColor:[UIColor blueColor]];

Installation

The recommended approach to use the YLProgressBar in your project is using the CocoaPods package manager, as it provides flexible dependency management and dead simple installation.

CocoaPods

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Go to the directory of your Xcode project, and Create and Edit your Podfile and add YLProgressBar:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios
pod 'YLProgressBar', '~> 3.11.0'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file)

$ open MyProject.xcworkspace

Manually

Download the project and copy the YLProgressBar folder into your project and then simply #import "YLProgressBar.h" in the file(s) you would like to use it in.

Contribution

Contributions are welcomed and encouraged .

Contact

Yannick Loriot

License (MIT)

Copyright 2012 - present, Yannick Loriot. http://yannickloriot.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ylprogressbar's People

Contributors

erdemtu avatar goff-marocchi avatar ioliverm avatar ipodishima avatar lexrus avatar mpurland avatar scottphc avatar siong1987 avatar yannickl 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  avatar  avatar  avatar

ylprogressbar's Issues

Text not updating sometimes

The bar fills correctly but sometimes the text gets stuck on a number. Specifically 10%. If I restart the app it allows the text to update. Clicking on items and removing them the progressbar and text go down normally. I am not using it in a download process more of an achievement tracking bar. Love YLProgressBar

Ensure that `stripesWidth` is not set to zero to prevent memory allocation issues

If you accidentally set stripesWidth to 0, then in the following piece of code in the drawStripes:(CGContextRef)context withRect:(CGRect)rect method in YLProgressBar.m

NSInteger start = -_stripesWidth;
    NSInteger end   = rect.size.width / (2 * _stripesWidth) + (2 * _stripesWidth);
    CGFloat yOffset = (_type == YLProgressBarTypeRounded) ? YLProgressBarSizeInset : 0;

    for (NSInteger i = start; i <= end; i++)
    {
        UIBezierPath *stripe = [self stripeWithOrigin:CGPointMake(i * 2 * _stripesWidth + _stripesOffset, yOffset)
                                               bounds:rect
                                          orientation:_stripesOrientation];
        [allStripes appendPath:stripe];
    }

will result in the allocation of 2147483647 UIBezierPath objects, because end will evaluate to 2147483647

minimumFontSize is deprecated

In Xcode Version 6.1.1 I get the following compiler warning
/Pods/YLProgressBar/YLProgressBar/YLProgressBar.m:323:25: 'minimumFontSize' is deprecated: first deprecated in iOS 6.0

AddressSanitizer: heap-buffer-overflow on address

Hello Yannick,

After running my app through the AddressSanitizer I got a heap buffer overflow error.
The lines causing that are in - (void)setProgressTintColor:(UIColor *)progressTintColor:

const CGFloat *c    = CGColorGetComponents(progressTintColor.CGColor);
UIColor *leftColor  = [UIColor colorWithRed:(c[0] / 2.0f) green:(c[1] / 2.0f) blue:(c[2] / 2.0f) alpha:(c[3])];

CGColorGetComponents is not guaranteed to return 4 components in all cases. In my case it returned 2 (color was white). To fix that, please replace the lines above with the following:

CGFloat red, green, blue, alpha;
[progressTintColor getRed:&red green:&green blue:&blue alpha:&alpha];
UIColor *leftColor  = [UIColor colorWithRed:(red / 2.0f) green:(green / 2.0f) blue:(blue / 2.0f) alpha:(alpha)];

Performance Issue - Multiple Progress Bar

Hello,

I am using multiple progress bars (in each table cell) to show progress for file uploading. Unfortunately, the view becomes very slow - despite the fact that the progress bars have been finished and the files have been uploaded. I noticed the the iPhone CPU is stacked to > 90%.

The "way" i finish the progress bar is:

YLProgressBar.progress = 1.0
YLProgressBar.YLProgressBar = YES.

Is this the correct way to stop "normally" the progress (times) or i have missed something?

Why is the text only shown at 30%?

I am using this control in my app

If I set it to 10% I don't see the text saying 10% on the bar. It only shows up if it goes above 30%. How can I fix that?

[_progressBarRoundedFat setProgress:0.1f animated:animated];

Swift3 set progress issue

it always goes to 100 whatever i set except 0.0.

progressBar.setProgress(10.0, animated: true)
progressBar.progress = 10.0

nothing works. always jumps to 100%.

Swift 3

Not compatible with Swift 3 and xcode 8

Antialiasing when rotated

Hi,

First of all thank you for your cool bar!

Would it be possible to antialias the drawing of the bar when rotated by a transform?
I'm not a pro with CA but i've tried to add

CGContextSetAllowsAntialiasing(theContext, true);
CGContextSetShouldAntialias(theContext, true);

to your drawing stuff with no result.

Draws outside of bounds at low end

The bar and stripes are drawn outside of the track at low values. This is due to the fact that the clipping region in those functions is defined as a rounded rect with the same parameters as the track, but the rectangle being drawn is much smaller, leading to a much less convex path. This is most visible in longer progress bars; in shorter ones it grows past this error quickly.

The solution is to clip by the larger path as well:

    UIBezierPath *roundedRect   = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) cornerRadius:self.cornerRadius];
    [roundedRect addClip];

A tip for "dealloc" method never be called

First of all, thank yannickl for this awesome project.

We imported the version 3.10.2 into our project, and found that the dealloc method was never called.

I found the _progressTargetTimer may never be invalid if the progress didn't reach the end.

- (void)updateProgressWithTimer:(NSTimer *)timer
{
CGFloat dt_progress = [timer.userInfo floatValue];
_progress += dt_progress;
if ((dt_progress < 0 && _progress <= _progressTargetValue)
|| (dt_progress > 0 && _progress >= _progressTargetValue))
{
[_progressTargetTimer invalidate];
_progressTargetTimer = nil;
_progress = _progressTargetValue;
}
[self setNeedsDisplay];
}

So I wrote this in the host view's dealloc method to invalidate the _progressTargetTimer:

_progressBar.progress = 0;

- (void)setProgress:(CGFloat)progress
{
[self setProgress:progress animated:NO];
}

- (void)setProgress:(CGFloat)progress animated:(BOOL)animated
{
@synchronized (self)
{
if (_progressTargetTimer && [_progressTargetTimer isValid])
{
[_progressTargetTimer invalidate];
}
CGFloat newProgress = progress;
if (newProgress > 1.0f)
{
newProgress = 1.0f;
} else if (newProgress < 0.0f)
{
newProgress = 0.0f;
}
if (animated)
{
_progressTargetValue = newProgress;
CGFloat incrementValue = ((_progressTargetValue - _progress) * YLProgressBarStripesAnimationTime) / YLProgressBarProgressTime;
self.progressTargetTimer = [NSTimer timerWithTimeInterval:YLProgressBarStripesAnimationTime
target:self
selector:@selector(updateProgressWithTimer:)
userInfo:[NSNumber numberWithFloat:incrementValue]
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_progressTargetTimer forMode:NSRunLoopCommonModes];
} else
{
_progress = newProgress;
[self setNeedsDisplay];
}
}
}

The dealloc method was called finally.

Issue with setProgress in swift3

I tried to use setProgress(0.0, animated: true) at first but when I get progress by "self.progressBar.progress" it's return 0.3 not 0.0 and I tried to set 0.3035. It's still return 0.3 for me.
Why it's not update?

Indicator text doesn't show

Xcode 6.3.2, using YLProgressBar in storyboard, neither YLProgressBarIndicatorTextDisplayModeProgress nor YLProgressBarIndicatorTextDisplayModeTrack displays the default text.
Here is the code below for reference:
// Initialize progress bar
self.progressBar.progressTintColor = [UIColor greenColor];
self.progressBar.indicatorTextDisplayMode = YLProgressBarIndicatorTextDisplayModeTrack;
self.progressBar.behavior = YLProgressBarBehaviorIndeterminate;

There is a white gap between border to progress bar

I created the progress bar from storyboard, I change the UIView class to YLProgressBar. and then set the color in viewDidLoad().

progressBar.progressTintColor = UIColor.magentaColor()
progressBar.trackTintColor = UIColor.whiteColor()
progressBar.type = YLProgressBarType.Rounded
progressBar.stripesOrientation = YLProgressBarStripesOrientation.Vertical
![Uploading iOS Simulator Screen Shot Apr 12, 2015, 12.49.58.png . . .]()

progressBar.stripesDirection = YLProgressBarStripesDirection.Left

But there is a gap on the left, as you can see from pic below
ios

Still slight gloss when turned off

There still seems to be a slight bit of white gloss when it's turned off, I would expect it to be completely flat. Would be great if you could address this

Using pods and storyboard

For some reason, i am not able to subclass the UIProgressView with YLProgressBar through storyboard, it doesnt show in inspector. I am using iOS 7 and installed via pods. Any help? Thanks

UIImage instead of indicatorTextLabel

Hi,

I am trying to place a UIImage instead of indicatorTextLabel, I have added attributed string on this label.. but the image is not showing in ylprogressbar.. it is though showing on any common label..

Could you pls guide me ?

Right to left support

Hi,
Is there any support for right to left applications. I am able to rotate the progress bar but with that the progress indicator also got mirrored.
I tried to rotate the progress bar with :

progressBar.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI))
self.progressBar.indicatorTextLabel.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI))

then the text label indicator also got mirrored and i am not able to undo that i.e only to rotate the progress bar, not the label.
screen shot 2017-11-21 at 5 33 23 pm

Thank you.

Remove gradiant

Hello,
How to remove gradient from flatProgress bar simple bar without black gradient at the begin

Show indicatorTextLabel.text on top of progress instead of getting overlapped

Hi,
First of all, what a great library. Thank-you for the effort!

My question.
I was wondering if it would be possible to have the indicatorTextLabel text show above the progress instead of getting overlapped (see screenshot where the text "SOME TEXT" starts to hide behind the progress bar)

screen shot 2016-06-30 at 4 52 55 pm

NSArray *tintColors = @[[UIColor colorWithRed:33/255.0f green:180/255.0f blue:162/255.0f alpha:1.0f],
                            [UIColor colorWithRed:149/255.0f green:37/255.0f blue:36/255.0f alpha:1.0f];
  _progressBarRoundedSlim.progressTintColors        = tintColors;

    _progressBarRoundedSlim.hideStripes = YES;
    _progressBarRoundedSlim.trackTintColor = [UIColor whiteColor];
    _progressBarRoundedSlim.progressBarInset = 3;

    _progressBarRoundedSlim.indicatorTextLabel.text = @"SOME TEXT";
    _progressBarRoundedSlim.hideGloss = YES;

    _progressBarRoundedSlim.indicatorTextDisplayMode = YLProgressBarIndicatorTextDisplayModeTrack;
    _progressBarRoundedSlim.indicatorTextLabel.font  = [UIFont fontWithName:@"Arial-BoldMT" size:20];
    _progressBarRoundedSlim.indicatorTextLabel.textColor = [UIColor blackColor];

Thank-you.

pod can't find 3.4.0

i got error
[!] Unable to satisfy the following requirements:
YLProgressBar (~> 3.4.0) required by Podfile

i use #pod search YLProgressBar
can't find version 3.4.0
1__lamb-mei_lamb-mei-mbp____dropbox_allpay_allpay_app_ios_app_allpay__zsh_

App crashes

I have added a UIView in custom cell and changed it's class to YLProgressBar but my app is crashing. I have also set flag false for showing stripes.
App is crashing in updateStripesTimer when setting self.stripesTimer = nil;

Using YLProgressBar with auto-layout?

Hi, in my app, I'm implementing auto-layout. When i try to implement YLProgressBar in my xib file, i'm getting "Failed to load designables from path (null)".

Can the question is how can i use this library in xib that contains auto-layout?

Any way to specify gradient colors that don't compress?

For instance, i have a progress bar that i want to go from blue to yellow to red. I specify _progressBar.progressTintColors = @[[UIColor bluecolor], [UIColor yellowColor], [UIColor redColor]] and then set it to 50%.

I get this:

|-blue.yellow.red-----------|

When I'd really like it to be:

|-blue.....yellow------------|

So the gradient colors are more of an indication of where the progress bar is at... you wouldn't see red at 50%, only blue to yellow. at 75% you'd see blue, yellow, and half of the gradient of yellow to red.

Does that make sense? Wondering if that's possible with the current codebase and if so, how would I achieve it?

Set corner radius

Can you add the possibility to change the value of the corder radius please?

I have a progress bar for questions

Can you set this effect? If the progress value is 120%, first 0-1, progress from left to right, then progress from right to left 0.2 (change another color)????????? Thank you very much!

Wrong colour shown

Hi, I've specified a particular colour for my progress bar but what is shown is different from what I specified.

Here is the screenshot:

screen shot 2016-08-12 at 4 31 29 pm

As seen in screenshot, the colour I wanted is selected under the properties which is light green (#8CE600) but wrong colour is shown in the xib file.

iOS7

in iOS7, issues, no animation.

Please add semantic version tags.

I’ve recently added <YLProgressBar> to the CocoaPods package manager repo.

CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

However, <YLProgressBar> doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags

Vertical gradient

Not sure if #15 meant a vertical progress bar, but I would like to have the colours show in a vertical gradient like I have done in the Pause button.
Is this possible currently? I can't seem to find any way...
Thanks!

screen shot 2016-08-25 at 1 56 10 pm

Documentation on stripesAnimated

I think it would be great if docs were more specific about disabling stripes animation. From examples I've understood that it's enough to just set hideStripes = YES. But I've run into performance degradation caused by stripesAnimated initially being set to YES.

Thanks!

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.