0

我想使用 UIPasteboard 实现一个剪贴板应用程序,它可以将纯文本和富格式、Web 内容复制到粘贴板上,然后显示在我的 TextView 或 WebView 上。我怎样才能做到这一点?

我有以下代码,它可以获取纯文本,但如果我复制网页内容怎么办?

if ([pasteboard containsPasteboardTypes:[NSArray arrayWithObjects:@"public.utf8-plain-text", @"public.text", nil]]){
    if (![_contentList containsObject:pasteboard.string]){
        NSLog(@"String representation present: %@", pasteboard.string);
        [self addContentList:pasteboard.string];
        [pasteboard setValue:@"" forPasteboardType:UIPasteboardNameGeneral];
    }

}
4

1 回答 1

0

尝试UIPasteboardTypeListString改用

[[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 
if (pasteboard.string != nil) {
    [self insertText:pasteboard.string]; 
}

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPasteboard_Class/Reference.html

于 2013-06-03T14:05:24.477 回答