gpt4 book ai didi

cocoa - 如何创建与 OS X 通知类似的警报?

转载 作者:行者123 更新时间:2023-12-03 17:33:34 25 4
gpt4 key购买 nike

从警报中,我假设这张图片代表的是一个面板,而不是一个工作表(我的理解是工作表覆盖在已经打开的应用程序上)。

我正在寻找创建一个自定义的,或者只是内置的“干净”弹出警报(通知)。我似乎在 NSAlert 中找不到任何涉及自定义警报的内容 -alertType 似乎可以,但显然它是为了传达重要性。

一个例子是这样的:

enter image description here

(来源:/image/WJhV8.jpg)

最佳答案

NSUserNotificationCenter类用于在屏幕右上角呈现这些“用户通知”:

notification example

import AppKit

let note = NSUserNotification()
note.title = "Hi Stack Overflow"
note.subtitle = "How’s it going?"
note.contentImage = NSImage(contentsOfURL: NSURL(string: "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png")!)

NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(note)

(您在 Gmail 中看到的是 Chrome 提供的自定义非标准通知系统。如果您编写 Chrome 扩展程序,您可能可以利用它,但 NSUserNotificationCenter 更为常见。)

关于cocoa - 如何创建与 OS X 通知类似的警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32853352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com