swift - 在 Mac Catalyst 中更改 NSToolbarItem 图像大小
问题描述
NSToolbarItem
使用添加自定义时,NSToolbarDelegate
我无法设置图标的图像。使用具有不同大小的默认值(SplitView 或 Share)时会出现问题:
这是其中两个项目的示例代码,一个是共享一个,另一个是添加一个新项目。另请注意,在我正在使用的共享示例中NSSharingServicePickerToolbarItem
,即使我正在覆盖它仍在使用“系统”图像的图像。
case .new:
let item = NSToolbarItem(itemIdentifier: itemIdentifier)
item.image = UIImage(systemName: "plus")
item.label = "New Card"
item.action = #selector(ViewController.didTapCreateNewToolbarButton(_:))
item.target = nil
toolbarItem = item
case .share:
let item = NSSharingServicePickerToolbarItem(itemIdentifier: itemIdentifier)
item.image = UIImage(systemName: "square.and.arrow.up")
item.label = "Share"
item.action = #selector(ViewController.didTapShareToolbarButton(_:))
item.target = nil
toolbarItem = item
我试过使用UIImage.SymbolConfiguration(pointSize: 8, weight: .medium)
,但结果是一样的。我也尝试过这个解决方案:https ://developer.apple.com/forums/thread/131364但结果是图像占用了整个可用空间(更大且像素化)。
那么,如何更改这些按钮的大小/样式?能够同时更改系统和我的自定义系统会很棒。
编辑 1:此问题仅在删除标题时出现,这使工具栏的高度更小,并正确调整系统按钮的大小,而不是其他按钮:
if let titlebar = windowScene.titlebar {
titlebar.toolbar = toolbar
titlebar.toolbarStyle = .automatic
titlebar.titleVisibility = .hidden // <-- THIS
}
解决方案
推荐阅读
- linux - 如何在 Manjaro Deepin 上添加守护程序 bash 命令以启动
- postman - HMAC 保护的 API 和 Postman 请求
- android - 如何在 Dart 中使用 encrypt 实现 rsa 加密
- regex - 正则表达式获取两个字符串之间的字符串
- java - 如何在 jTextPane 中使用拉绳创建和填写表单?
- authentication - Route [murid.index] not defined. (View: D:\xampp\htdocs\MentorOnlinemu\resources\views\navigation-menu.blade.php)
- java - 如何在 Java 中将 object[] 转换为 char[]?
- javascript - 使用 Kraken WS API 制作的应用程序可能存在 React Memory 泄漏
- javascript - 在谷歌应用脚本的html代码中导入html文件
- kendo-grid - 如何使用与 Kendo Grid 相同的局部视图作为详细信息模板或仅在 Html 页面上