osx开发,NSAlert的使用
下面是代码
NSAlert *alert = [[NSAlert alloc]init];
//可以设置产品的icon
alert.icon = [NSImage imageNamed:@"Icon.png"];//your logo
//添加两个按钮吧
[alertaddButtonWithTitle:@"Got it"];
//[alert addButtonWithTitle:@"Cancel"];
//正文
alert.messageText = @"Login Failed";
//描述文字
alert.informativeText = @"Please check your email and password.";
//弹窗类型 默认类型 NSAlertStyleWarning
[alertsetAlertStyle:NSAlertStyleWarning];
//回调Block
[alertbeginSheetModalForWindow:[self window] completionHandler:^(NSModalResponse returnCode) {
if(returnCode ==NSAlertFirstButtonReturn) {
//Got it;
//这里写需要执行的操作
}
}];
回调的block中监听点击了哪个按钮returnCode ==NSAlertFirstButtonReturn,点到框架里查看发现,可以在系统的NSAlert添加三个按钮