I have a NSOutlineView with a list of parents item and children.
What's the easiest way to make the parent items (those ones with the opening arrow) in bold text?
thanks
If you are using a cell-based outline view, you can use this delegate method to bold parent items:
// Assuming you use NSTextFieldCell
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if ([self outlineView:outlineView numberOfChildrenOfItem:item] > 0) {
[(NSCell *)cell setFont: [NSFont boldSystemFontOfSize: ((NSCell *)cell).font.pointSize]];
} else {
[(NSCell *)cell setFont: [NSFont systemFontOfSize: ((NSCell *)cell).font.pointSize]];
}
}
Otherwise, in a view-based outline view you can do the following:
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
NSTableCellView *cellView = [outlineView makeViewWithIdentifier:@"MyIdentifier" owner:self];
if ([self outlineView:outlineView numberOfChildrenOfItem:item] > 0) {
[cellView.textField setFont: [NSFont boldSystemFontOfSize: cellView.textField.font.pointSize]];
} else {
[cellView.textField setFont: [NSFont systemFontOfSize: cellView.textField.font.pointSize]];
}
// do whatever else you do
return cellView;
}
Alternatively, NSOutlineViewDelegate's -outlineView:isGroupItem: might be what you're actually looking for: https://developer.apple.com/library/mac/documentation/cocoa/reference/NSOutlineViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSOutlineViewDelegate/outlineView:isGroupItem: