Last active
September 29, 2015 22:40
-
-
Save paulw11/84fc8db04947552ce36d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FadingLabel.h | |
// TextCrossFade | |
// | |
// Created by Paul Wilkinson on 30/09/2015. | |
// Copyright © 2015 Paul Wilkinson. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface FadingLabel : UILabel | |
-(void) embiggen; | |
-(void) debiggen; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FadingLabel.m | |
// TextCrossFade | |
// | |
// Created by Paul Wilkinson on 30/09/2015. | |
// Copyright © 2015 Paul Wilkinson. All rights reserved. | |
// | |
#import "FadingLabel.h" | |
@implementation FadingLabel | |
/* | |
// Only override drawRect: if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
- (void)drawRect:(CGRect)rect { | |
// Drawing code | |
} | |
*/ | |
-(void) embiggen { | |
CGSize newSize = [self.text boundingRectWithSize:CGSizeMake(self.frame.size.width, MAXFLOAT) | |
options:NSStringDrawingUsesLineFragmentOrigin | |
attributes:@{ | |
NSFontAttributeName : self.font | |
} | |
context:nil].size; | |
CGRect newRect = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, newSize.height); | |
self.frame = newRect; | |
[UIView transitionWithView:self duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ | |
self.numberOfLines = 0; | |
} completion:^(BOOL finished) { | |
// self.backgroundColor = [UIColor orangeColor]; | |
}]; | |
} | |
-(void) debiggen { | |
CGSize newSize = [@" " boundingRectWithSize:CGSizeMake(self.frame.size.width, MAXFLOAT) | |
options:NSStringDrawingUsesLineFragmentOrigin | |
attributes:@{ | |
NSFontAttributeName : self.font | |
} | |
context:nil].size; | |
CGRect newRect = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, newSize.height); | |
self.frame = newRect; | |
[UIView transitionWithView:self duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ | |
self.numberOfLines = 1; | |
} completion:^(BOOL finished) { | |
// self.backgroundColor = [UIColor greenColor]; | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment