2015-09-29 45 views
0

从警报,我假设这张图片代表的是一个面板,而不是一张纸(我的理解是,张是覆盖已经打开的应用程序)。如何创建类似于OS X通知的警报?

我正在寻找创建一个自定义,或只是建立在'干净'弹出警报(通知)。我似乎无法在NSAlert中找到任何说明定制警报的内容 - alertType似乎可能,但显然它是传达重要性的。

一个例子是这样的:

enter image description here

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

回答

3

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