假设 - 用户在 textField/textView/webView 中选择并复制了一些文本。
现在我想记录复制的文本,但不知道如何?
这怎么可能?
萨加尔
假设 - 用户在 textField/textView/webView 中选择并复制了一些文本。
现在我想记录复制的文本,但不知道如何?
这怎么可能?
萨加尔
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.utf8-plain-text"]]) {
NSLog(@"WE gots a string which is: %@", pasteboard.string);
}
希望这有帮助!;)
我的猜测是使用 UIPasteBoard 函数:http: //developer.apple.com/iphone/library/documentation/UIKit/Reference/UIPasteboard_Class/Reference.html
希望有帮助!
好的,Sagar 来了……你最好研究一下它是如何工作的:
此代码将字符串复制到粘贴板:
-(IBAction)copyStringToPasteBoard{
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom" create:YES];
appPasteBoard.persistent = YES;
NSString *yourCopiedText = @"YOUR TEXT HERE";
NSLog(@"\n Your String: %@",appPasteBoard.string);
[appPasteBoard setString:textView.text];
}
我希望这对你来说更具体,请投票给我^.^
我是 Objective-c 开发的新手,所以我可能会弄错,但 NSLog 行不应该低于“[appPasteBoard ...”行吗?在将文本实际写入粘贴板之前记录文本。
无论如何,这都是一个绝妙的例子,我稍加调整就使用了它。我想使用一般的粘贴板,所以我最终得到了这个:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *yourCopiedText = @"YOUR TEXT HERE";
[pasteboard setString:yourCopiedText];
NSLog(@"\n String sent to pasteboard: %@",pasteboard.string);
希望它可以帮助任何人,并感谢 Neurofluxation 的例子!
问候亨里克