NSOpenPanel* panel = [NSOpenPanel openPanel];
__weak typeof(self)weakSelf = self;
//是否可以创建文件夹
panel.canCreateDirectories = YES;
//是否可以选择文件夹
panel.canChooseDirectories = YES;
//是否可以选择文件
panel.canChooseFiles = YES;
//是否可以多选
[panel setAllowsMultipleSelection:NO];
//显示
[panel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result) {
//是否点击open 按钮
if (result == NSModalResponseOK) {
//NSURL *pathUrl = [panel URL];
NSString *pathString = [panel.URLs.firstObject path];
weakSelf.urlTextField.stringValue = pathString;
}
}];
// 悬浮电脑主屏幕上
// [panel beginWithCompletionHandler:^(NSInteger result) {
//
// }];
效果如下图