【问题标题】:How to create alerts that look similar to OS X notifications?如何创建类似于 OS X 通知的警报?
【发布时间】:2015-09-29 20:38:55
【问题描述】:

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

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

一个例子是这样的:

(来源:http://i.stack.imgur.com/WJhV8.jpg

【问题讨论】:

    标签: cocoa nsalert


    【解决方案1】:

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

    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 更正常。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 2016-04-07
      相关资源
      最近更新 更多