【问题标题】:How to remove NSTableView indentation on Big Sur如何在 Big Sur 上删除 NSTableView 缩进
【发布时间】:2021-02-23 17:41:13
【问题描述】:

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

调试界面时,我可以看到边缘包含表格行。这意味着单元格没有占据行的整个宽度。

如果有办法让单个单元格视图扩大整个表格视图的宽度,请告诉我。

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      if #available(macOS 11.0, *) {
          self.tableView.style = .plain
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-30
        • 1970-01-01
        • 2021-07-03
        • 1970-01-01
        • 1970-01-01
        • 2021-06-19
        • 2021-08-04
        • 2021-05-31
        相关资源
        最近更新 更多