Skip to content

Commit

Permalink
Merge pull request #43 from hsoi/hsoi-documentation-update
Browse files Browse the repository at this point in the history
Documentation update
  • Loading branch information
dataxpress committed Dec 10, 2015
2 parents 8965590 + abc7984 commit c108038
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Simply initialize a `UICountingLabel` the same way you set up a regular `UILabel

UICountingLabel* myLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(10, 10, 100, 40)];
[self.view addSubview:myLabel];
[myLabel release];

You can also add it to your XIB file, just make sure you set the class type to `UICountingLabel` instead of `UILabel` and be sure to `#import "UICountingLabel.h"` in the header file.

Expand All @@ -26,11 +25,26 @@ You can also add it to your XIB file, just make sure you set the class type to `
Set the format of your label. This will be filled with a single int or float (depending on how you format it) when it updates:

myLabel.format = @"%d";

Alternatively, you can provide a `UICountingLabelFormatBlock`, which permits greater control over how the text is formatted:

myLabel.fomatBlock = ^(NSString *)(CGFloat progress) {
NSInteger years = value / 12;
NSInteger months = (NSInteger)value % 12;
if (years == 0) {
return [NSString stringWithFormat: @"%ld months", (long)months];
}
else {
return [NSString stringWithFormat: @"%ld years, %ld months", (long)years, (long)months];
}
};

There is also a `UICountingLabelAttributedFormatBlock` to use an attributed string. If the `formatBlock` is specified, it takes precedence over the `format`.

Optionally, set the mode. The default is `UILabelCountingMethodEaseInOut`, which will start slow, speed up, and then slow down as it reaches the end. Other options are described below in the Methods section.

myLabel.method = UILabelCountingMethodLinear;

When you want the label to start counting, just call:

[myLabel countFrom:50 to:100];
Expand All @@ -57,6 +71,12 @@ Behind the scenes, these convinient methods use one base method, which has the f
You can get current value of your label using `-currentValue` method (works correctly in the process of animation too):

CGFloat currentValue = [myLabel currentValue];

Optionally, you can specify a `completionBlock` to perform an acton when the label has finished counting:

myLabel.completionBlock = ^{
NSLog(@"finished counting");
};

## Formats #####

Expand Down

0 comments on commit c108038

Please sign in to comment.