我尝试使用 Swift 在 Mac OS 上显示一些通知横幅。但我只在通知中心得到它们,而不是作为横幅。
你有想法吗?这是我的简单代码:
func showNotification() -> Void {
let notification = NSUserNotification()
notification.title = "Title of notification"
notification.subtitle = "Subtitle of notification"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(notification)
}
@IBAction func btnPressed(_ sender: NSButton) {
showNotification()
testLbl.stringValue = "Button was pressed"
}
Run Code Online (Sandbox Code Playgroud)