gpt4 book ai didi

objective-c - NSOutlineView : how to make parent items bold?

转载 作者:行者123 更新时间:2023-12-03 16:35:46 27 4
gpt4 key购买 nike

我有一个 NSOutlineView,其中包含父项目和子项目的列表。

将父项(带有开始箭头的项)设置为粗体文本的最简单方法是什么?

谢谢

最佳答案

如果您使用基于单元格的大纲 View ,则可以使用此委托(delegate)方法将父项加粗:

// 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]];
}
}

否则,在基于 View 的大纲 View 中,您可以执行以下操作:

- (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;
}

或者,NSOutlineViewDelegate-outlineView:isGroupItem: 可能就是您真正要寻找的:https://developer.apple.com/library/mac/documentation/cocoa/reference/NSOutlineViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSOutlineViewDelegate/outlineView:isGroupItem :

关于objective-c - NSOutlineView : how to make parent items bold?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25076136/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com