美文网首页
关于Mac复制粘贴之NSPasteBoard

关于Mac复制粘贴之NSPasteBoard

作者: Living_元宝儿 | 来源:发表于2022-12-05 10:20 被阅读0次

复制:

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];  //必须清空,否则setString会失败。
[pasteboard setString:@"something" forType:NSStringPboardType];

粘贴:

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *types = [pasteboard types];
if ([types containsObject:NSPasteboardTypeString]) {
NSString *s = [pasteboard stringForType:NSPasteboardTypeString];
        //do something..     
}

相关文章

网友评论

      本文标题:关于Mac复制粘贴之NSPasteBoard

      本文链接:https://www.haomeiwen.com/subject/pngbfdtx.html