NSTextField truncation with trailing ellipsis?

I'd like my NSTextFields to truncate their content with trailing ellipsis. I'm using these in an NSTableView. What I'm getting is tail-truncation at *word boundaries* and no ellipsis. My code is below. Line 7 sets a lineBreakMode on the cell, but that line has no effect. I could set it to .byTruncatingMiddle or any other value or delete it altogether and the NSTextField will still tail-truncate on word boundaries with no ellipsis. MacOS Sierra.


    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
        var view = tableView.make(withIdentifier: "cellID", owner: nil) as? NSTextField
        if view == nil {
            view = NSTextField(labelWithString: "")
            view!.identifier = "cellID"
            view!.font = NSFont.systemFont(ofSize: 12)
            view!.cell?.lineBreakMode = .byTruncatingTail
        }
        if tableColumn?.identifier == "Foo" {
            // String to tail-truncate...
            view!.stringValue = "The quick brown fox jumped over the lazy dog"
        }
        else {
            view!.stringValue = "Blah blah blah blah blah"
        }
        return view
    }
Accepted Answer

I should have posted this question sooner. It would have saved me a lot of time because, of course, I figured it out right after I posted. Line 7 should be:


view!.cell?.truncatesLastVisibleLine = true
NSTextField truncation with trailing ellipsis?
 
 
Q