在做macOS app开发的时候,常常使用NSOutlineView/NSTableView来展示数据,有很多列时,当拖拽窗口需要实现所有列的宽同时在默认设置的宽的基础上等比扩大或缩小。
1 2 3 4 5 6 |
//当拖拽窗口大小,NSOutlineView frame自动更改时,Column宽等比增减 [self.treeView setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle]; //最后一行自动宽等比增减 // [self.treeView sizeLastColumnToFit]; //app第一次运行Column 自动宽等比增减,否则会有滚动条 [self.treeView sizeToFit]; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
typedef NS_ENUM(NSUInteger, NSTableViewColumnAutoresizingStyle) { /* Turn off column autoresizing */ NSTableViewNoColumnAutoresizing = 0, /* Autoresize all columns by distributing equal shares of space simultaeously */ NSTableViewUniformColumnAutoresizingStyle, /* Autoresize each table column one at a time. Proceed to the next column when the current column can no longer be autoresized (when it reaches maximum/minimum size). */ NSTableViewSequentialColumnAutoresizingStyle, // Start with the last autoresizable column, proceed to the first. NSTableViewReverseSequentialColumnAutoresizingStyle, // Start with the first autoresizable column, proceed to the last. /* Autoresize only one table column one at a time. When that table column can no longer be resized, stop autoresizing. Normally you should use one of the Sequential autoresizing modes instead. */ NSTableViewLastColumnOnlyAutoresizingStyle, NSTableViewFirstColumnOnlyAutoresizingStyle }; |