NSTableView - change GroupRow style

Viewed 1142

I'm trying to mimic what the MacOS contacts app does with GroupRows in my own app, but can't figure out or find anywhere how to get rid of the lines above and below the group row. I tried adding my own custom NSTableRowView and can change the background color with no problem, but no idea how to get rid of those borders.

The lines above and below the D & L

This is from the contacts app

2 Answers

Plus, we can omit custom variable isGroupRow instead using built-in isGroupRowStyle if you set [self tableView:tableView isGroupRow:row] correctly.

Below Swift snippet creates a floating grouped styled table view row -- looks quite like Finder. In which, isGroupRowStyle differentiates normal rows from group rows; isFloating is true when a group row is not anchored on top of table view; overriding drawBackground(in:) removes separators wrapped around a group row.

class TableRowView: NSTableRowView {

    override func draw(_ dirtyRect: NSRect) {
        guard isGroupRowStyle && isFloating else {
            return super.draw(dirtyRect)
        }

        NSColor.gridColor.setFill()
        dirtyRect.fill()
    }

    override func drawBackground(in dirtyRect: NSRect) {
        // do not draw
    }
}
Related