MBPopup
MBPopup 是一个用于轻松将可自定义的状态栏弹出窗口添加到您的应用程序的 macOS 框架。
MBPopup 基于 shpakovski 的 Popup,在 HAPU 中使用了 3 年以上,并逐步改进,现在用 Swift 重写,并对 Swift 时代进行了改进。
更重要的是,已经重写了多个部分,以复制系统菜单栏项的行为
- 在有正确的事件时打开
- 按 Esc 键关闭
- 允许预览(点击以打开,释放以关闭)
- 在从不同的(非)活动屏幕单击时打开正确的屏幕
- 根据期望更改焦点
- 等。
同时,
- 根据期望响应用户布局约束
- 为用户操作提供回调
- 允许在使用修饰键时使用不同的状态
MBPopup 已获得 App Store 批准,目前正在使用应用 stts
用法
(有关更多示例,请参阅 示例 项目,或 stts 的源代码)
通过 Carthage 添加 MBPopup
Cartfile
github "inket/MBPopup"
或通过 CocoaPods
Podfile
pod "MBPopup"
在您的应用程序中使用 MBPopup
import MBPopup
let myView = NSView(frame: CGRect(x: 0, y: 0, width: 200, height: 300))
let popupController = MBPopupController(contentView: myView)
// Use popupController.statusItem to customize the NSStatusItem, set a title or an image
popupController.statusItem.title = "Test"
popupController.statusItem.length = 70
// Use popupController.backgroundView to customize the popup's background
popupController.backgroundView.backgroundColor = NSColor.windowBackgroundColor // Default value
// Customize animations, view sizes
popupController.openDuration = 0.15 // Default value
popupController.closeDuration = 0.2 // Default value
popupController.arrowSize = CGSize(width: 12, height: 8) // Default value
popupController.contentInset = 1 // Default value
// Use callbacks to user actions (optional)
popupController.shouldOpenPopup = { keys in return true }
popupController.willOpenPopup = { keys in debugPrint("Will open popup!") }
popupController.didOpenPopup = { debugPrint("Opened popup!") }
popupController.willClosePopup = { debugPrint("Will close popup!") }
popupController.didClosePopup = { debugPrint("Closed popup!") }
// Resize your popup to your liking
popupController.resizePopup(width: 300, height: 400)