Search code examples
cocoa

NSTableView content view inset


I am looking to inset the contents of an NSTableView so that there is a gap between the top of the table view and the first cell.

On iOS this is easy with UITableView - achieved by using setContentInset:.


Solution

  • Turn headers back on and substitute the header view with your own subclass. Override its -drawRect: to draw only your background color. Also override -headerRectOfColumn: to prevent any of the column headers from being drawn. I'm not sure if this prevents column dragging or sorting but I'll bet it does.

    Update: Isaiah’s answer from 2019 should now be the correct answer. A lot has changed since my answer!