Skip to content

Instantly share code, notes, and snippets.

@fidanov
Created February 13, 2014 14:24
Show Gist options
  • Save fidanov/8975842 to your computer and use it in GitHub Desktop.
Save fidanov/8975842 to your computer and use it in GitHub Desktop.
#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