Trim text in UILabel with quotes?

By default, UILabels trims text and then puts an ellipsis at the end.

How can I wrap all text, including an ellipse, in double quotes?

+3
source share
5 answers
UILabel *label;
label.lineBreakMode = UILineBreakModeMiddleTruncation;
+1
source

If there is no even more convenient method on the iPhone that I don’t know about, I think that the simplest and most flexible task would be to subclass UILabel and implement my own drawing and truncation, using various sizeWithFont extensions to determine the width of the string and each set of quotes individually.

+1
source

(, , )? , , , , , UILabels ( ). .

0

UILable s, ( ), :

["text that is lon…]["]
0

, . :

. . sizeWithFont: constrainedToSize: lineBreakMode: . , , . :

NSString *nextLine = rawTextWithoutQuotes;
NSRange range = [nextLine rangeOfString: @" " options: NSBackwardsSearch];
if (range.location == NSNotFound) {
    return nextLine;
} else {
    nextLine = [nextLine substringToIndex: range.location];
}

, , , , .

0
source

Source: https://habr.com/ru/post/1726636/


All Articles