I have a label (NSTextField) with text aligned right. When the text becomes too large to display, the end of the text is truncated (at the right edge of the label). In my case I would actually want to truncate the beginning of the text. How can I achieve this in the Interface Builder or in code?
Now
| This sentence is to |
Desired
| entence is too long |
I'm not quite sure if this works for NSTextFields, I know it does for UILabels, but have you tried :
myTextField.lineBreakMode = NSLineBreakMode.ByTruncatingHead
What you're looking for is
[[myTextField cell] setLineBreakMode: NSLineBreakByTruncatingHead];
Swift:
myTextField.cell.lineBreakMode = NSLineBreakMode.ByTruncatingHead
来源:https://stackoverflow.com/questions/28322946/truncate-beginning-of-label