Giter Site home page Giter Site logo

kaprogresslabel's Introduction

Language CocoaPods Compatible Build Status

KAProgressLabel

Circular progress label for iOS with styling, animations, interaction and more.

Demo 1

KAProgressLabel

Demo 2

Endless possibilities! KAProgressLabel

Installing

Lame install

  • Copy the KAProgressLabel/KAProgressLabel folder into your project.
  • Import KAProgressLabel.h from your .pch file

Using CocoaPods

Add this line to your Podfile:

pod 'KAProgressLabel'

Usage

Style

Colors

self.myProgressLabel.fillColor = [UIColor blackColor];
self.myProgressLabel.trackColor = [UIColor redColor];
self.myProgressLabel.progressColor = [UIColor greenColor];

Widths

self.myProgressLabel.trackWidth = 2.0;         // Defaults to 5.0
self.myProgressLabel.progressWidth = 4;        // Defaults to 5.0
self.myProgressLabel.roundedCornersWidth = 10; // Defaults to 0

Start and end labels

A (very) small text can be display at the start and end of the progress arc, via 2 dedicated labels. You can style this label any way you want.

self.myProgressLabel.startLabel.text = @"S";
self.myProgressLabel.endLabel.text = @"E";

Arc

Progress

If you only want to show a progress, it's straightforward.

// Progress must be between 0 and 1
self.myProgressLabel.progress = 0.5;

Specific start/end degrees

- (void)setStartDegree:(CGFloat)startDegree;
- (void)setEndDegree:(CGFloat)endDegree;

User interaction

You can allow the user to interact with both startDegree and endDegree. By default, user interaction is disabled.

// Activate user interaction on both sides
self.myProgressLabel.isStartDegreeUserInteractive = YES;
self.myProgressLabel.isEndDegreeUserInteractive = YES;

Animations

You can animate startDegree, endDegree and progress.

- (void)setStartDegree:(CGFloat)startDegree
               timing:(TPPropertyAnimationTiming)timing
             duration:(CGFloat)duration
                delay:(CGFloat)delay;

- (void)setEndDegree:(CGFloat)endDegree
             timing:(TPPropertyAnimationTiming)timing
           duration:(CGFloat)duration
              delay:(CGFloat)delay;

- (void)setProgress:(CGFloat)progress
            timing:(TPPropertyAnimationTiming)timing
          duration:(CGFloat)duration
             delay:(CGFloat)delay;

It's possible to stop an already started animation.

- (void)stopAnimations;

You can also add some custom logic at the end of an animation using the labelAnimCompleteBlock block.

self.myProgressLabel.labelAnimCompleteBlock = ^(KAProgressLabel *label) {
    NSLog(@"Animation complete !");
};

kaprogresslabel's People

Contributors

942v avatar alexgaribay avatar alexiscreuzot avatar blixt avatar cariosvertel avatar codyhazelwood avatar infolock avatar revolter avatar stevesparks avatar ulazdins 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

kaprogresslabel's Issues

Crashes on Multiple Animations

I am a bit surprised that no one else reported that issue and thus assume that there is an error on my side, but I report it anyway:

I don't only animate KAProgressLabel, but make it interactive. I.e., on touch (of some other control), the label fills up and on releasing it, the label's progress decreases again. Now, the first time this happens for a KAProgressLabel instance, it works well, but once you touch that control a second time โ€“ and the KAProgressLabel instance gets animated a second time โ€“, it crashes.

The sole reason for this seems to be that TPPropertyAnimation *_currentAnimation is marked __unsafe_unretained. I really don't see why you did this. Simply removing the __unsafe_unretained fixes the issue for me.

This is fully consistent and reproducible for me to the point that, over the last couple of months, every time I re-install or update my pods, I first run into that crash again, then realize that CocoaPods has overwritten my fix, remove the __unsafe_unretained again and everything works fine again (I couldn't see any way how I can fix it permanently with a category or subclass).

As said, I am surprised that on one has reported that issue yet and so assume that there is an error on my side and am happy if someone could point me to it. Just in case I'm correct, though, please remove the __unsafe_unretained and push an update (as said, I really don't see why you have it there in the first place).

Thanks.

typo in the readme.md

hey

shouldn't it be label.text = [NSString.. ?

- (void)viewDidLoad { self.myProgressLabel.labelVCBlock = ^(KAProgressLabel *label) { label.text:[NSString stringWithFormat:@"%.0f%%", (label.progress * 100)]; };

Progress Label Text change automatically

Hi

When I am using

`self.pLabel.progress = 0.75;`

then I can successfully change pLabel text
But when I am using

`[self.pLabel setProgress:0.75 timing:TPPropertyAnimationTimingEaseInEaseOut duration:1 delay:0];`

then pLabel text in not updating and it's showing percentage instead of text.

It's bug ?

Incorrect use of KVO is causing crashes

If a KAProgressLabel is deallocated, the app will crash with the following:

Thread : Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x00000001874ca530 __exceptionPreprocess + 132
1  libobjc.A.dylib                0x00000001984a00e4 objc_exception_throw + 60
2  CoreFoundation                 0x00000001874ca470 -[NSException initWithCoder:]
3  Foundation                     0x00000001883465e0 NSKVODeallocate + 340
4  UIKit                          0x000000018bcd2cb8 -[UIView(Hierarchy) removeFromSuperview] + 700
5  UIKit                          0x000000018bcd5944 -[UIView dealloc] + 448
6  UIKit                          0x000000018bdca120 -[UITableViewCellContentView dealloc] + 108
7  CoreFoundation                 0x00000001873a9378 CFRelease + 524
8  CoreFoundation                 0x00000001873b5938 -[__NSArrayM dealloc] + 152
9  libobjc.A.dylib                0x00000001984b9724 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 564
10 CoreFoundation                 0x00000001873acf94 _CFAutoreleasePoolPop + 28
11 Foundation                     0x00000001882d2fe4 -[NSAutoreleasePool release] + 148
12 UIKit                          0x000000018bdb8c58 -[UITableView layoutSubviews] + 192
13 UIKit                          0x000000018bcd54a4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
14 QuartzCore                     0x000000018b6297a8 -[CALayer layoutSublayers] + 168
15 QuartzCore                     0x000000018b624378 CA::Layer::layout_if_needed(CA::Transaction*) + 320
16 QuartzCore                     0x000000018b62421c CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
17 QuartzCore                     0x000000018b623a14 CA::Context::commit_transaction(CA::Transaction*) + 276
18 QuartzCore                     0x000000018b623798 CA::Transaction::commit() + 436
19 UIKit                          0x000000018bcd7424 _UIApplicationHandleEventQueue + 1800
20 CoreFoundation                 0x0000000187482d34 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
21 CoreFoundation                 0x0000000187481fd8 __CFRunLoopDoSources0 + 264
22 CoreFoundation                 0x0000000187480088 __CFRunLoopRun + 712
23 CoreFoundation                 0x00000001873ad1f4 CFRunLoopRunSpecific + 396
24 GraphicsServices               0x00000001907cf6fc GSEventRunModal + 168
25 UIKit                          0x000000018bd3e10c UIApplicationMain + 1488
26 Roger                          0x00000001000d764c main (main.m:6)
27 libdyld.dylib                  0x0000000198b1ea08 start + 4

To fix this issue, make sure that all KVO is removed in dealloc.

iOS 8 issue, progress drawed not in center

Since iOS 8 progress label drawing at 3 pixels to right and bottom, because drawRect: pass rect with nonzero origin.
Possible fix:

...
    CGFloat archXPos = rect.size.width/2  + rect.origin.x;
    CGFloat archYPos = rect.size.height/2 + rect.origin.y;
...

How to use labelVCBlock in swift??

lblProgress.labelVCBlock = ^(KAProgressLabel *label) {
label.text = [NSString stringWithFormat:@"%.f", (label.progress/100)*total*100];
};

Breakpoint with Nan

hello,

awesome stuff so far. except, now it crashes with a breakpoint in the following lines:

self.startLabel.frame = [self rectForDegree:_startDegree andRect:rect];
self.endLabel.frame = [self rectForDegree:_endDegree andRect:rect];

with _endDegree showing Nan.

this is the stack:
erminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(0x185cbc2d8 0x1979880e4 0x185cbc218 0x18a064a60 0x18a0649b8 0x1009edf58 0x18a064948 0x18ac19360 0x18a72db6c 0x18a73d9fc 0x100237dfc 0x10023677c 0x18a7b7960 0x18a09ec20 0x18a088da0 0x18a08837c 0x18a087f00 0x18a068a18 0x18a0686d0 0x18a067e58 0x18a067bd8 0x18a061300 0x185c742a4 0x185c71230 0x185c71610 0x185b9d2d4 0x18f5f36fc 0x18a79af40 0x1000512b8 0x198032a08)
libc++abi.dylib: terminating with uncaught exception of type NSException

How to fix this? Thank you very much. It used to work in previous versions

TPPropertyAnimation RunLoop change causes UI updates in non-main thread

I took the latest version of the code and started getting UI update in other than main thread exceptions.
Looked at the diff to what I had been using and found the following line had changed:

    [timer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; // TODO/ custom loop mode 

when I returned the code to use NSDefaultRunLoopMode the problem went away.

Add tvOS Support

Can the podspec include tvos?

I think you want to change this:

s.platform = :ios

into something like this:

s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'

UIScrollView or TextView scroll event blocks UIView animation

Hi I'm using progress label to show a countdown timer with animation.
My view has a scrollview and a textview with kaprogresslabel.
And if i scroll one of them.
kaprogresslabel's setStartDegree: with TPPropertyAnimationTimingLinear animation breaks

i read http://stackoverflow.com/questions/16557846/uiscrollview-scroll-event-blocks-uiview-animation

and I change

  • (void)addAnimation:(TPPropertyAnimation *)animation {

    if ( !animations ) {
    animations = [[NSMutableArray alloc] init];
    }

    [animations addObject:animation];

    if ( !timer ) {
    if ( NSClassFromString(@"CADisplayLink") != NULL ) {
    timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(update:)];
    // #revision
    //[timer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [timer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    // ##
    } else {
    timer = [NSTimer scheduledTimerWithTimeInterval:kRefreshRate target:self selector:@selector(update:) userInfo:nil repeats:YES];
    }
    }
    }

in TPPropertyAnimation.m

I changed NSRunLopp mode to NSRunLoopCommonModes

and it works fine for me now
fyi

A possible enhancement......

Hello,
Thanks for your excellent tool.
I would like to propose a possible enchancement...
Can you make to set up your tool programmatically and not only in IB?
Because when I tried to do it I got a crash and some warnings because of weak set up.
Thanks again.

George Gerardis

Animate bar from startAngle to endAngle

Right now it's only possible to animate the bar from angle 0 degrees to a certain angle, which ignores _startDegree.
It would be great to be able to animate it from any start angle to any end angle.

Animation has not been stopped correctly

Current implementation of the stop animation might cause SIGABRT when it's called twice.
The reason is when the cancel function itself remove the object. But the _currentAnimation might still point to them in a short period. This lead to an invalid reference and cause SIGABRT

- (void) stopAnimations
{
    if (_currentAnimation != nil) {
        [_currentAnimation cancel];
         }
}

Proposal:

- (void) stopAnimations
{
    if (_currentAnimation != nil) {
        [_currentAnimation cancel];
      _currentAnimation = nil;
         }
}

Default roundedCornerWidth doesn't match progressWidth = 4

This configuration worked in v2.1.

screen shot 2015-03-19 at 4 50 46 pm

Here's how I set it up:

KAProgressLabel *uploadProgress = [[KAProgressLabel alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
uploadProgress.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
uploadProgress.center = CGPointMake(self.contentView.bounds.size.width - 36, self.contentView.center.y);
uploadProgress.hidden = YES;
uploadProgress.progressWidth = 4;
uploadProgress.trackColor = [UIColor colorForRogerProgressBackground];
uploadProgress.trackWidth = 6;
[self.contentView addSubview:uploadProgress];
self.uploadProgress = uploadProgress;

the fill color in circle mode was wrong

should be

    // The Circle
    CGContextSetFillColorWithColor(context, fillColor.CGColor);
    CGContextSetLineWidth(context, _backBorderWidth);
    CGContextFillEllipseInRect(context, circleRect);
    CGContextStrokePath(context);

Crash in example

If in example project press "animate" and after animation finished press "stop" application crashes.

2016-05-31 22:18:19.094 KAProgressLabel[66969:6503461] -[__NSCFType cancel]: unrecognized selector sent to instance 0x7ae4f890
2016-05-31 22:18:19.133 KAProgressLabel[66969:6503461] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType cancel]: unrecognized selector sent to instance 0x7ae4f890'
*** First throw call stack:
(
    0   CoreFoundation                      0x01fc1746 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x01c4aa97 objc_exception_throw + 44
    2   CoreFoundation                      0x01fc9705 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
    3   CoreFoundation                      0x01f10287 ___forwarding___ + 1047
    4   CoreFoundation                      0x01f0fe4e _CF_forwarding_prep_0 + 14
    5   KAProgressLabel                     0x000fd57f -[KAProgressLabel stopAnimations] + 79
    6   KAProgressLabel                     0x000fb3a0 -[Demo1 selectStop:] + 112
    7   libobjc.A.dylib                     0x01c607cd -[NSObject performSelector:withObject:withObject:] + 84
    8   UIKit                               0x003f5a40 -[UIApplication sendAction:to:from:forEvent:] + 99
    9   UIKit                               0x003f59d2 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    10  UIKit                               0x0053613a -[UIControl sendAction:to:forEvent:] + 69
    11  UIKit                               0x00536557 -[UIControl _sendActionsForEvents:withEvent:] + 598
    12  UIKit                               0x005357c1 -[UIControl touchesEnded:withEvent:] + 660
    13  UIKit                               0x0044dcaa -[UIWindow _sendTouchesForEvent:] + 874
    14  UIKit                               0x0044e786 -[UIWindow sendEvent:] + 792
    15  UIKit                               0x0040c681 -[UIApplication sendEvent:] + 242
    16  UIKit                               0x0041cab8 _UIApplicationHandleEventFromQueueEvent + 21484
    17  UIKit                               0x003f02e7 _UIApplicationHandleEventQueue + 2300
    18  CoreFoundation                      0x01ee306f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    19  CoreFoundation                      0x01ed8b7d __CFRunLoopDoSources0 + 253
    20  CoreFoundation                      0x01ed80d8 __CFRunLoopRun + 952
    21  CoreFoundation                      0x01ed7a5b CFRunLoopRunSpecific + 443
    22  CoreFoundation                      0x01ed788b CFRunLoopRunInMode + 123
    23  GraphicsServices                    0x03b912c9 GSEventRunModal + 192
    24  GraphicsServices                    0x03b91106 GSEventRun + 104
    25  UIKit                               0x003f40b6 UIApplicationMain + 1526
    26  KAProgressLabel                     0x00102bba main + 138
    27  libdyld.dylib                       0x03708ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Animation in TableView not showing while scrolling

If the ProgressLabel is used in a TableView Cell it will not update its animation while scrolling. To support updates during scrolling the NSTimer for the animation needs to run in NSRunLoopCommonModes:

This needs to be changed in TPPropertyAnimation.m:

`- (void)addAnimation:(TPPropertyAnimation *)animation {

if ( !animations ) {
    animations = [[NSMutableArray alloc] init];
}

[animations addObject:animation];

if ( !timer ) {
    if ( NSClassFromString(@"CADisplayLink") != NULL ) {
        timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(update:)];
        [timer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    } else {
        timer = [NSTimer scheduledTimerWithTimeInterval:kRefreshRate target:self selector:@selector(update:) userInfo:nil repeats:YES];
    }
}

}`

This should probably not be standard implementation, but in case someone needs it, it should be documented somewhere.

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.