Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove NSTableView indentation on Big Sur

Big Sur added a new property style, that defaults to automatic. Even though I'm setting it to full width, I can still see a difference between my app running on Xcode 12.1 vs 12.2 This is a sample app with a simple cell drawing its background red. enter image description here

When debugging the interface I can see that the edges contain the table row. Which means that the cell is not occupying the entire full width of the row. enter image description here

Please let me know if there is a way to get a single cell view to expand the entire tableview width.

Here is the sample application: https://www.dropbox.com/s/zx4qqncllja1sox/test.zip?dl=0

like image 849
the Reverend Avatar asked Nov 11 '20 17:11

the Reverend


2 Answers

.fullWidth actually includes horizontal padding at the row level.

You will need to set tableView.style = .plain to get back the pre-Big Sur look and feel.

From the NSTableView header files:

@available(macOS 11.0, *)
public enum Style : Int {       
    // Automatically infers the effectiveStyle from the table view hierarchy.
    case automatic = 0

    // Edge-to-edge style with standard content padding at the ends of each row. This content padding is constant and independent of intercellSpacing.
    case fullWidth = 1

    // Inset style with rounded corners selection
    case inset = 2

    /* The source list style of NSTableView. Setting this style will have the side effect of setting the background color to "source list".
     Additionally in NSOutlineView, the following properties may change to get the standard "source list" look: indentationPerLevel, rowHeight and intercellSpacing. After setting the style it is possible to change any of the other properties as required.
     In 10.11, if the background color has been changed from the "source list" background color to something else, the table will no longer draw the selection as a source list blur style, and instead will draw a normal selection highlight.
     This replaces NSTableViewSelectionHighlightStyleSourceList which is to be deprecated.
     */
    case sourceList = 3

    // A plain style. No insets, padding or any other kind of decoration applied to the row or its background. The cells are equally spaced in the row using intercellSpacing.width.
    case plain = 4
}
like image 140
ctietze Avatar answered Sep 23 '22 05:09

ctietze


☝️ An interesting observation. You can set plain style in Interface Builder but many people report that it doesn't work. Seems like it won't be applied if you compile not on Big Sur. In that case, like other answers suggest, specifying style in code does the trick:

if #available(macOS 11.0, *) {
    self.tableView.style = .plain
}
like image 32
Ian Bytchek Avatar answered Sep 24 '22 05:09

Ian Bytchek