I have a custom UIView class, and in the - (void)drawRect:(CGRect)rect I want to draw some text. However I want the text block to be limited to a maximum width of 84px at a system font size of 12. If the text exceeds this width, I want to cut it and make the last 3 character to be “…”.
Example:
"This is some text" // length okay
"Information co..." // length truncated
I know that I can calculate the width of a string with a given font through NSString‘s - (CGSize)sizeWithFont:(UIFont *)font, but how can I get the maximum string length for 84px width?
If I am understanding your situation correctly, then you should use the method
- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakModeand use UILineBreakModeTailTruncation for the line break mode.