objective-c - 如何在 NSOutlineView 中设置本地化的显示/隐藏按钮

标签 objective-c macos cocoa

我的应用程序中有 NSOutlineView。这个功能

-(BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item

将outlineView中的一些项目设置为组根(如果函数返回YES)+在单元格末尾添加显示/隐藏按钮以展开/折叠该组的内容,但是这个按钮是用英文写的。我来自白俄罗斯,这就是为什么我想要显示/隐藏用我的语言写的单词。 Finder 以我的语言编写,这就是为什么我认为,有一些选项可以为其设置本地化样式。 我该怎么做?

已解决: Mac OS 在选择包含 NSOutineView

的 .nib 文件的本地化时自行执行此操作

最佳答案

检索本地化显示/隐藏按钮(以及披露按钮)的官方方法现在是 documented在 NSOutlineView 类引用中。

let showHideButton = outlineView.makeViewWithIdentifier(NSOutlineViewShowHideButtonKey, owner: outlineView.delegate()) as? NSButton

重要的是要注意按钮的 state 属性控制隐藏/显示标题,默认情况下它不会与 NSOutlineView 的状态同步:

  • NSOnState = "隐藏"
  • NSOffState = "显示"

NSOutlineViewDisclosureButtonKey The normal triangle disclosure button.

NSOutlineViewShowHideButtonKey The Show/Hide button.

The outline view creates these buttons by calling its inherited makeViewWithIdentifier:owner: method, passing in the key as the identifier and the delegate as the owner.

These keys are backwards compatible to OS X v10.7, however, the symbol is not exported prior to v10.9 and the string value (@"NSOutlineViewDisclosureButtonKey") must be used.

关于objective-c - 如何在 NSOutlineView 中设置本地化的显示/隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8631982/

相关文章:

objective-c - Objective C 初始化器基础

ios - UIImage RBG 值在保存到设备库时发生变化

ios - Swift:切片 startIndex 始终为 0

macos - rsync 备份到外部硬盘 exFat 失败

objective-c - 提取包含关键字的句子 Objective c

iphone - 我如何更改分隔线,以便它们在 UITableView 中的填充单元格后消失

macos - 无法连接到 Neo

objective-c - 如何为 objective-c /cocoa mac osx 应用程序实现试用期?

macos - 像 Preview.app 一样将 NSScrollView 的文档 View 居中?

ios - Reactive Cocoa - try catch 并重播