将NSAttributedString复制到粘贴板 [英] Copy NSAttributedString to pasteboard

查看:198
本文介绍了将NSAttributedString复制到粘贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全新的Cocoa和我试图找出如何复制NSAttributedString到粘贴板。



这里是我必须复制一个常规的NSString:

  NSPasteboard * pb = [NSPasteboard generalPasteboard]; 
NSArray * types = [NSArray arrayWithObjects:NSStringPboardType,nil];
[pb declareTypes:types owner:self];

[pb setString:@asdfasdfforType:NSStringPboardType];

如何设置NSAttributedString?



感谢

解决方案

您想要NSRTFPboardType或NSRTFDPboardType以及NSAttributedString的 RTFFromRange:documentAttributes: code> / RTFDFromRange:documentAttributes: setData

Brand new to Cocoa and I'm trying to figure out how to copy an NSAttributedString to the pasteboard. I've looked in the docs and not sure if I'm supposed to use a NSPasteboardItem or not.

Here's what I have to copy a regular NSString:

NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil];
[pb declareTypes:types owner:self];

[pb setString:@"asdfasdf" forType:NSStringPboardType];

How do I set a NSAttributedString?

Thanks

解决方案

You want either NSRTFPboardType or NSRTFDPboardType along with the NSAttributedString's RTFFromRange:documentAttributes:/RTFDFromRange:documentAttributes: and setData on the pasteboard.

这篇关于将NSAttributedString复制到粘贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆