Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // NSString+StringSizing.m
- // Complete
- //
- // Created by Erik Villegas on 8/13/14.
- // Copyright (c) 2014 Complete. All rights reserved.
- //
- #import "NSString+StringSizing.h"
- @implementation NSString (StringSizing)
- - (CGFloat) heightUsingFont:(UIFont *) font {
- NSParameterAssert(font);
- return [self sizeConstrainedToWidth:CGFLOAT_MAX height:CGFLOAT_MAX font:font].height;
- }
- - (CGFloat) widthUsingFont:(UIFont *) font {
- NSParameterAssert(font);
- return [self sizeConstrainedToWidth:CGFLOAT_MAX height:CGFLOAT_MAX font:font].width;
- }
- - (CGFloat) heightConstrainedToWidth:(CGFloat) width usingFont:(UIFont *) font {
- NSParameterAssert(font);
- return [self sizeConstrainedToWidth:width height:CGFLOAT_MAX font:font].height;
- }
- - (CGFloat) widthConstrainedToHeight:(CGFloat) height usingFont:(UIFont *) font {
- NSParameterAssert(font);
- return [self sizeConstrainedToWidth:CGFLOAT_MAX height:height font:font].width;
- }
- - (CGSize) sizeUsingFont:(UIFont *) font {
- NSParameterAssert(font);
- return [self sizeConstrainedToWidth:CGFLOAT_MAX height:CGFLOAT_MAX font:font];
- }
- - (CGSize) sizeConstrainedToWidth:(CGFloat) width height:(CGFloat) height font:(UIFont *) font {
- NSParameterAssert(font);
- CGSize size = [self boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font} context:NULL].size;
- return CGSizeMake(ceilf(size.width), ceilf(size.height));
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement