views:

401

answers:

4

By default, UILabels truncate text and then put an ellipsis on the end.

How might I wrap all the text, including the ellipse, in double quotes?

A: 
UILabel *label;
label.lineBreakMode = UILineBreakModeMiddleTruncation;
kubi
Did you even read the question?
Azeem.Butt
Maybe I misunderstood it. The OP is currently getting '"Some line of ...' and they want '"Some... of text"', which setting middle truncation will give them.
kubi
+1  A: 

Unless there's an even better convenience method on the iPhone that I don't know about, I think the easiest and most flexible thing to do would be to subclass UILabel and implement your own drawing and truncation, using the various sizeWithFont extensions to determine the width of the string and each set of quotes individually.

Azeem.Butt
Do you think it's possible to set the font/color of the quotes using this method?
Andrew Johnson
A: 

Is your label text predictably going to result in truncation (and thus always have the ellipse)? I doubt it, but in case it does, you know the content is going to basically fill the width, so you can make the quote marks other UILabels (or even images). This would give you font and color control as well.

pluckyglen
A: 

Use two UILables, the first holds the text (plus an open-quote), and the second just holds a close-quote:

["text that is lon…]["]
Vincent Gable