Last active
December 9, 2015 21:19
-
-
Save jdriscoll/4329965 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
// | |
// UITextView+Dimensions.h | |
// | |
// Created by Justin Driscoll on 1/6/12. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UITextView (Dimensions) | |
+ (CGFloat)heightWithText:(NSString *)text font:(UIFont *)font atWidth:(CGFloat)width; | |
@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
// | |
// UITextView+Dimensions.m | |
// | |
// Created by Justin Driscoll on 1/6/12. | |
// | |
#import "UITextView+Dimensions.h" | |
// This represents the total vertical and horizontal padding applied to the text. | |
// We have to subtract this from our original width and add it to the resulting | |
// height to get the correct dimensions. | |
static const CGFloat marginAdjustment = 16.0; | |
@implementation UITextView (Dimensions) | |
+ (CGFloat)heightWithText:(NSString *)text font:(UIFont *)font atWidth:(CGFloat)width | |
{ | |
CGSize bounds = CGSizeMake(width - marginAdjustment, CGFLOAT_MAX); | |
CGSize size = [text sizeWithFont:font | |
constrainedToSize:bounds | |
lineBreakMode:NSLineBreakByWordWrapping]; | |
return size.height + marginAdjustment; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update for ios 7?