views:

538

answers:

1

Hi,

I am drawing a NSString using drawAtPoint (drawInRect, that makes no big difference). There is a parameter to set the line break mode, but has anyone an idea how to append "..." to strings if they are truncated?

One option is, to check whether the string is short enough. If that is not the case, iteratively remove the last character until the string length + 3 euqals the maximum length.

I am sure there is a better solution. Anyone an idea?

Best,

heinrich

+1  A: 

You'd better to use another NSString method:

- (CGSize)drawAtPoint:(CGPoint)point 
             forWidth:(CGFloat)width 
             withFont:(UIFont *)font 
        lineBreakMode:(UILineBreakMode)lineBreakMode

And specify UILineBreakModeTailTruncation as lineBreakMode.

Valerii Hiora