I have a string placed in a rectangle. If it doesn’t Appropriately, I need to find the index of the character to be replaced with an ellipsis and delete the rest of the string.
Edit:
As suggested by James Bedford’s answer, This problem can be solved by adding UIKit NSString.
[foo drawInRect:someRect withFont:someFont
lineBreakMode:UILineBreakModeTailTruncation];
UILineBreakModeTailTruncation and When drawing together, an ellipsis will be added at the end of the string.
Edit:
The best thing I can do is to write an algorithm that uses these sizeWithFont: methods to try each string length you want, until the character The string no longer fits in the box. At this point, you know that you need to return three characters to make room for the ellipsis. You should be able to optimize this algorithm to O(log(n)).
I’m looking for an iOS target equivalent to Android Paint.breakText() c.
I have a string placed in a rectangle. If it doesn’t fit, I need to find The index of the character replaced by the ellipsis and delete the rest of the string.
Edit:
As suggested by James Bedford’s answer, this question can be solved by adding UIKit NSString To solve.
[foo drawInRect:someRect withFont:someFont
lineBreakMode:UILineBreakModeTailTruncation];
When UILineBreakModeTailTruncation is used with drawing, it will be in Add an ellipsis at the end of the string.
Have you tried using the sizeWithFont: method in the NSString UIKit Additions category, referenced here?
Edit:
The best thing I can do is to write an algorithm that uses these sizeWithFont: methods to try each string length you want, until the character The string no longer fits in the box. At this point, you know that you need to return three characters to make room for the ellipsis. You should be able to optimize this algorithm to O(log(n)).