如何在Big Sur上删除NSTableView缩进

时间:2020-11-11 17:58:40

标签: xcode macos cocoa nstableview macos-big-sur

Big Sur添加了新的属性样式,默认为自动。即使将其设置为全角,我仍然可以看到在Xcode 12.1和12.2上运行的应用程序之间存在差异 这是一个示例应用程序,带有一个简单的单元格,将其背景绘制为红色。 enter image description here

调试接口时,我可以看到边缘包含表格行。这意味着该单元格不会占用该行的整个完整宽度。 enter image description here

请让我知道是否有一种方法可以使单个单元格视图扩展整个表视图宽度。

以下是示例应用程序:https://www.dropbox.com/s/zx4qqncllja1sox/test.zip?dl=0

2 个答案:

答案 0 :(得分:7)

.fullWidth实际上包括在行级别的水平填充。

您需要设置tableView.style = .plain才能恢复大苏尔之前的外观。

NSTableView头文件中:

@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
}

答案 1 :(得分:1)

☝️ 一个有趣的观察。您可以在 Interface Builder 中设置普通样式,但 many people report 它不起作用。如果你在 Big Sur 上编译not,它似乎不会被应用。在这种情况下,就像其他答案所建议的那样,在代码中指定样式就可以了:

q38