Mar 28 2010
So far as I can tell, the iPhone SDK exposes no method to truncate an NSString to a given width (in pixels). This function obviously exists since it is used when drawing UILabels, and you can even draw truncated text with the method:
- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont*)font lineBreakMode:(UILineBreakMode)lineBreakMode
… but there’s no way to read-back the rendered text.
A quick search of the ‘net revealed some methods which would truncate a string based on the number of characters, but nothing to perform the operation based on the rendered width in pixels.