Skip to content

Instantly share code, notes, and snippets.

@adison
Last active January 14, 2022 06:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adison/41bcfe6d8608505844ed109bfb1d08f7 to your computer and use it in GitHub Desktop.
Save adison/41bcfe6d8608505844ed109bfb1d08f7 to your computer and use it in GitHub Desktop.
make source list style nsoutlineview programmatically
NSScrollView* container = [[NSScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
container.hasVerticalScroller = YES;
container.hasHorizontalScroller = YES;
container.wantsLayer = YES;
container.identifier = [@(LOGVIEW_OFFSET + i) stringValue];
NSClipView* clipview = [[NSClipView alloc] init];
clipview.autoresizesSubviews = YES;
clipview.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
NSOutlineView* outline = [[NSOutlineView alloc] init];
outline.selectionHighlightStyle = NSTableViewSelectionHighlightStyleSourceList;
outline.floatsGroupRows = NO;
outline.indentationPerLevel = 16.f;
outline.indentationMarkerFollowsCell = NO;
outline.wantsLayer = YES;
outline.layer.backgroundColor = [NSColor secondarySelectedControlColor].CGColor;
// outline code
NSTableColumn* col1 = [[NSTableColumn alloc] initWithIdentifier:@"col1"];
col1.editable = NO;
col1.minWidth = 300000.f;
col1.headerCell.stringValue = [NSString stringWithFormat:@"DUT%lu", dutIndex];
[outline addTableColumn:col1];
[outline setOutlineTableColumn:col1];
container.contentView = clipview;
clipview.documentView = outline;
@adison
Copy link
Author

adison commented Sep 6, 2016

There are 2 points:
1: the clipped view
2: the table column and outlinetablecolumn

@hannesoid
Copy link

thanks! not knowing of outlinetablecolumn drove me crazy

@JoeyBodnar
Copy link

Very nice, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment