Created
February 13, 2014 14:24
-
-
Save fidanov/8975842 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
#import "Utilities.h" | |
@implementation Utilities | |
+ (CGSize)text:(NSString *)text sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size { | |
if(IOS_NEWER_OR_EQUAL_TO_7) { | |
CGRect frame = [text boundingRectWithSize: size | |
options: (NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) | |
attributes: @{NSFontAttributeName: font} | |
context:nil]; | |
return frame.size; | |
} else { | |
return [text sizeWithFont:font constrainedToSize:size]; | |
} | |
} | |
+ (CGFloat)text:(NSString *)text heightWithFont:(UIFont *)font constrainedToWidth:(CGFloat)width | |
{ | |
return [self text:text sizeWithFont:font constrainedToSize:CGSizeMake(width, MAXFLOAT)].height; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment