小编Hei*_*amp的帖子

使用 Swift 在 Mac 上显示通知横幅

我尝试使用 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)

macos notifications swift

7
推荐指数
1
解决办法
2031
查看次数

标签 统计

macos ×1

notifications ×1

swift ×1