Last active
September 8, 2015 21:23
-
-
Save dhrrgn/8b9637f25ab0bcfc7306 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
RCT_EXPORT_METHOD(measureTextRect:(NSString *)string withWidth:(double)width withFontName:(NSString *)fontName andFontSize:(double)fontSize andCallback:(RCTResponseSenderBlock)callback) | |
{ | |
UIFont *font = [UIFont fontWithName:fontName size:fontSize]; | |
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]; | |
CGRect rect = [string boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) | |
options:NSStringDrawingUsesLineFragmentOrigin | |
attributes:attributes | |
context:nil]; | |
callback(@[ | |
@{ | |
@"height": [NSNumber numberWithFloat:rect.size.height], | |
@"width": [NSNumber numberWithFloat:rect.size.width], | |
} | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment