简体   繁体   English

NSWindow调整大小时调整表列大小

[英]Resize Table Column when NSWindow resizes

I am working on a Cocoa application in which I am using NSTableView. 我正在使用NSTableView的Cocoa应用程序上工作。

Now I want the widths of the columns in the table view to be auto-resized when the user resizes or maximizes the window, by either dragging the application from a corner, or by clicking the zoom button. 现在,我希望通过用户从角落拖动应用程序或单击缩放按钮来在用户调整窗口大小或最大化窗口时自动调整表视图中列的宽度。

Any help will be appreciated. 任何帮助将不胜感激。

Make sure your table view itself resizes when the window resizes, by setting up constraints or setting its autoresizing mask. 通过设置约束或设置其自动调整大小的掩码,确保在窗口调整大小时表格视图本身也能调整大小。

Then set the table's overall column autoresizing style. 然后设置表的整体列自动调整大小样式。 In a storyboard or XIB, you do this by selecting the table view (not the scroll view that contains it) and then setting the “Column Sizing” popup in the Attributes inspector. 在情节提要或XIB中,可以通过选择表视图(而不是包含它的滚动视图),然后在“属性”检查器中设置“列大小”弹出窗口来执行此操作。 In code, you set the table view's columnAutoresizingStyle . 在代码中,设置表格视图的columnAutoresizingStyle The different styles are described under NSTableViewColumnAutoresizingStyle . 不同的样式在NSTableViewColumnAutoresizingStyle下进行描述。 If you want all of the columns to expand or contract during a resize, set it to NSTableViewUniformColumnAutoresizingStyle . 如果您希望所有列在调整大小期间扩展或收缩,请将其设置为NSTableViewUniformColumnAutoresizingStyle

Then set up each column's autoresizing behavior if necessary. 然后根据需要设置每列的自动调整大小行为。

If you are setting up your table in a XIB or storyboard, you can select the column and then set its resizing behavior under the Attributes inspector. 如果要在XIB或情节提要中设置表,则可以选择该列,然后在“属性”检查器下设置其大小调整行为。

If you are creating a column in code, set the resizingMask of each NSTableColumn to include whichever resizing mode bits you want. 如果您在代码中创建一个列,设置resizingMask每个NSTableColumn包括任何你想要的大小调整模式位。 The default is to allow both user resizing and autoresizing, so you shouldn't need to do anything. 默认设置是允许用户调整大小和自动调整大小,因此您无需执行任何操作。

如果摆弄列调整大小掩码或tableView调整大小设置没有任何作用,请确保最后一列实际上触及了表格视图的右侧,即使看起来确实如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM