NSTextField’s attributedString and truncating

I have a NSTextField in a table cell view. Since it can be to long to show, I set the line break as Truncate Middle in interface builder. But no matter how I tried, the truncating just did not work.

After some investigation, I found the problem is that I set the ‘’’attributed string’’’ explicitly and it overrides the line break setting by interface builder. I have to set it when I made up the attributed string.

let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .ByTruncatingMiddle

let attributes = [NSParagraphStyleAttributeName:paragraph]

attributedString.addAttributes(attributes, range:  range )

It is pretty obvious when you know the problem. Of course the setting of line break in interface building is overridden by the attributedString. It’s just the same as the the setting of text color, background color and so on. The line break setting is under Control section. I think that’s why I was confused in the first place.