Skip to content

Instantly share code, notes, and snippets.

@paulw11
Last active September 29, 2015 22:40
Show Gist options
  • Save paulw11/84fc8db04947552ce36d to your computer and use it in GitHub Desktop.
Save paulw11/84fc8db04947552ce36d to your computer and use it in GitHub Desktop.
//
// 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
//
// 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