如何创建类似于 MAC 升级通知的面板



屏幕截图

就像这样,在右上角,就像OS X升级通知一样。我尝试了NSAlert,cor NSPanel,但失败了。我想知道如何创建它,或者它不是一个系统类?

您要

查找的类是 NSUserNotification ,您可以在其中设置通知的标题和说明,然后再显示通知。

在那里玩一下这些选项,让它们适合您。

顺便说一句:有两种NSUserNotification样式可供选择。简单的和附有动作的。遗憾的是,每个应用只能使用一种类型,因为此值是在 .plist 文件中设置的。

以下是我前段时间编写的一些代码,用于通过NSUserNotifactionCenter显示错误通知:

- (void)postErrorNotificationWithTitle:(NSString *)title subtitle (NSString*)subtitle description:(NSString *)description {
    NSUserNotification* userNoti = [[NSUserNotification alloc] init]; //create the notification with all its information
    userNoti.title = title;
    userNoti.subtitle = subtitle;
    userNoti.informativeText = description;
    NSBeep(); //create error sound
    [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNoti]; //Add and remove the notification from the notification center, we only want to display it
    [[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:userNoti];
}

最新更新