Created
April 17, 2012 04:11
-
-
Save ktakayama/2403396 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
@interface UILabel (ktlib) | |
- (void) fitSizeOfFont:(UIFont *)font; | |
@end |
This file contains hidden or 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
#import "UILabel+ktlib.h" | |
@implementation UILabel (ktlib) | |
- (void) fitSizeOfFont:(UIFont *)font { | |
NSString *label = self.text; | |
CGFloat width = self.frame.size.width; | |
CGFloat height = self.frame.size.height; | |
CGSize constraintSize = CGSizeMake(width, MAXFLOAT); | |
CGSize labelSize; | |
int i; | |
for(i = font.pointSize; i > self.minimumFontSize; i--) { | |
font = [font fontWithSize:i]; | |
labelSize = [label sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; | |
if(labelSize.height <= height) | |
break; | |
} | |
self.font = font; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment