2013-06-03 47 views
0

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

我有以下代码,它可以得到纯文本,但如果我复制一个web内容呢?

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]; 
    } 

} 

回答

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

+0

我认为这只能抓一个字符串,如果我复制一个什么样的网页内容?如html? – zolibra

+0

请参阅此处的富文本答案 - http://stackoverflow.com/a/12603189/46297不知道从网页上复制时是否会起作用。 – lostInTransit

+0

这不是这种情况,我想要的是从UIPasteboard获取内容,但没有在其中设置内容。 – zolibra