How to Get an NSTableView with No Borders and No Insets on Big Sur?
- 2 minutes read - 252 wordsMacOS Big Sur has arrived and it has a new style for table views. This new style makes rows taller and also adds some space to each row, insetting them.
While you may like your app to adopt this look for most of your tables, it is possible that some tables look odd when insetted. There is a new style attribute you can apply both in IB and in code, which by default is set to automatic. What this means is that depending on the configuration of your table, the effectiveStyle resolved by the system might give an inset or not.
It might be the heuristics or how Xcode configures the table, but I had to try so many combinations to get it working exactly how I wanted: an NSTableView with no borders and no insets, that looks the same on Catalina and on Big Sur.
How Do I Fix It?
The trick is to leave all the defaults in IB: the scroll view with the bezelled border and the table view style set to automatic.
Then in your view controller, configure the table view style and the scroll view:
// Set style to plain to prevent any inset.
if #available(OSX 11.0, *) {
tableView.style = .plain
}
// By default the enclosing scrollview has a bezelled border, but we set
// it to no border here after the tableview style has been set to plain.
tableView.enclosingScrollView?.borderType = .noBorder
This fixes this particular issue on Big Sur while preserving the behavior on Catalina.