macos - 为 MacOS 自定义 Electron 中的工具栏
问题描述
我一直在寻找有关 MacOS 中工具栏自定义的 Electron 文档。默认工具栏只有窗口按钮和页面标题,如下图所示。
这是默认工具栏,我想插入一些按钮并对其进行自定义,因为它是 Swift 中的 NSToolbar。
任何想法都会很棒
解决方案
您可以通过传递道具titleBarStyle: hidden
const win = new BrowserWindow({ titleBarStyle: 'hidden' })
这会将标准窗口控件(交通灯)保留在您的网页内容之上。
然后,您可以通过将 html 元素定位在工具栏应该在的位置来“自定义”您自己的工具栏。
确保添加:
#menu-bar {
....
...
-webkit-app-region: drag;
}
到您的菜单栏元素。
https://www.electronjs.org/docs/api/frameless-window#hidden https://www.electronjs.org/docs/api/frameless-window#windows-control-overlay
或者您可以查看 custom-electron-titlebar 库
推荐阅读
- r - RStudio / R - 使列中的值与字符串完全匹配的行的新df(需要更快的速度)
- ios - Alamofire 5 替代 sessionDidReceiveChallenge
- javascript - 如何用组类覆盖元素类
- mule - 为什么 Multipart/form-data 删除 Nill 以响应 Mule Dataweave
- java - 如何忽略@Where休眠
- pointers - Go 中的 BigInt 指针
- python - 使用 Pandas 从 url 读取 excel
- microsoft-teams - 如何将 Microsoft Teams 连接到我的网站?
- ios - 在 iOS 记录事件后从 Firebase Analytics 发送邮件
- javafxports - javafx TableView上的自动水平滚动