Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into cyril94440-master
  • Loading branch information
TomKnig committed Nov 11, 2014
2 parents a71f810 + 644f1ad commit 1c38204
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions Classes/TOMSMorphingLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
@property (nonatomic, assign, getter=isMorphingEnabled) BOOL morphingEnabled;

- (void)setTextWithoutMorphing:(NSString *)text;
- (void)setText:(NSString*)text withCompletionBlock:(void (^)(void))block;

@end
22 changes: 21 additions & 1 deletion Classes/TOMSMorphingLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

#define kTOMSKernFactorAttributeName @"kTOMSKernFactorAttributeName"

@interface TOMSMorphingLabel ()
@interface TOMSMorphingLabel (){
void (^_block)(void);
}

@property (readonly, nonatomic, assign) NSUInteger numberOfAttributionStages;
@property (readonly, nonatomic, strong) NSArray *attributionStages;
Expand Down Expand Up @@ -261,6 +263,18 @@ - (void)setText:(NSString *)text
}
}

- (void)setText:(NSString*) text withCompletionBlock:(void (^)(void))block{
_block = block;
if (self.isMorphingEnabled) {
self.nextText = text ? text : @"";
if (self.displayLinkDuration > 0) {
[self beginMorphing];
}
} else {
super.text = text;
}
}

- (void)setAttributionStage:(NSInteger)attributionStage
{
@synchronized (self) {
Expand Down Expand Up @@ -399,6 +413,12 @@ - (void)endMorphing
if (self.nextText) {
[self beginMorphing];
}
else{
if(_block != nil){
_block();
_block = nil;
}
}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ - (void)viewDidLoad {
label.textAlignment = NSTextAlignmentCenter;

[self.view addSubview:label];
[self toggleTextForLabel:label];
[label setText:@"Test" withCompletionBlock:^{
NSLog(@"First label animation completed");
}];
[self performSelector:@selector(toggleTextForLabel:) withObject:label afterDelay:2];
}

#pragma mark - toggling text
Expand Down

0 comments on commit 1c38204

Please sign in to comment.