Created
October 29, 2012 08:31
-
-
Save MosheBerman/3972372 to your computer and use it in GitHub Desktop.
Working text to dialog array
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
// | |
// Calculates the substring that fits in a frame | |
// | |
- (NSString *) substringThatFitsFrame:(CGRect)frame withFont:(UIFont *)font{ | |
NSString *truncatedString = self; | |
CGSize clippingSize = CGSizeMake(frame.size.width, CGFLOAT_MAX); | |
CGSize size = [truncatedString sizeWithFont:font constrainedToSize:clippingSize lineBreakMode:NSLineBreakByClipping]; | |
NSMutableArray *components = [[truncatedString componentsSeparatedByString:@" "] mutableCopy]; | |
while (frame.size.width <= size.width || frame.size.height <= size.height) { | |
[components removeLastObject]; | |
truncatedString = [components componentsJoinedByString:@" "]; | |
size = [truncatedString sizeWithFont:font constrainedToSize:clippingSize lineBreakMode:NSLineBreakByClipping]; | |
} | |
return truncatedString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment