我已经看到一些 Catalyst 应用程序向 NSToolbar 添加了一个搜索栏,我想知道我如何才能做到这一点。我是否必须导入 AppKit/Cocoa 才能获得 NSSearchField 和实际的 NSToolbar?或者我没有看到 UISearchBars 有什么方法吗?任何帮助都会很棒,谢谢。
我曾尝试导入 AppKit 和 Cocoa(使用捆绑加载器),但我认为我做得不对。如果有人有关于如何执行此操作的可靠指南,请链接它。
我还尝试使用 UISearchBar 的自定义视图创建 UIBarButtonItem,它最终不会呈现任何内容。(可以在下面找到)
这是在 itemIdentifier.rawValue 的 switch case 中找到的(在工具栏 itemForIdentifier 函数中)
let search = UISearchBar()
search.sizeToFit()
let button = UIBarButtonItem(customView: search)
button.width = 100
let toolbarItem = NSToolbarItem(itemIdentifier: itemIdentifier, barButtonItem: button)
toolbarItem.isBordered = true
toolbarItem.isEnabled = true
return toolbarItem
Run Code Online (Sandbox Code Playgroud)