概述
NSAlert是macOS应用上的一种提示或者警告弹窗,它允许你指定提示文本,按钮标题以及自定义图标等等。基本的显示样式如下:
具体实现
//创建一个alert实例
let alert = NSAlert()
// set Message
alert.messageText = "are you sure you want to remove your marked notes?";
// set informative text
alert.informativeText = "Marked ontes will also be removed on other devices signed into your account".
//set accessory View
alert.accessory = NSView()
//help
alert.showsHelp = true;
alert.delegete = self;
func alertShowHelp(_ alert:NSAlert) ->Bool{}
//suppression checkbox
alert.showsSuppressionButton = true;
alert.suppressionButton = cutomBtn;
//response button
alert.addButton(withTitle:"Cancel");
//set type
alert.alertStyle = NSAlert.Style.warning
//弹出弹框
func beginSheetModal(for sheetWindow: NSWindow, completionHandler handler: ((NSApplication.ModalResponse) -> Void)? = nil)
复制代码
弹出弹框还有一种方式 open func runModal() -> NSApplication.ModalResponse
这种方式是弹出模态窗口,也就是必须先关闭当前弹框之后,才能对其他窗口进行操作。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END