Reputation: 11
Hi~ I have one question. ^^
How can i get "selected text" on UIWebView (or UITextView) ?
I'd like to copy "selected text" without copy/paste popup-view.
1) i removed ... copy/paste view. ( it was success~ )
UIMenuController *theMenu = [UIMenuController sharedMenuController];
[theMenu setMenuVisible:NO];
[theMenu update];
2. forced copy "selected text" (fail)
copyController.h -------------------------
@interface copyController : UIViewController <UIWebViewDelegate>
{
UIWebView *WebView;
}
copyController.m ------------------------
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
// ----------> here !!!!!
// I'd like to forced copy "selected text" without copy/paste popup-view
// ** How can i get selected text ???**
return [super canPerformAction:action withSender:sender];
}
- (void)copy:(id)sender
{
UIPasteboard *board = [UIPasteboard generalPasteboard];
NSLog(@"SENDER : copied : %@",board.string);
}
How can i copy text in canPerformAction. ?
The reason I want to copy "selected text" is just for decorating text by changing color and font.
thx you~
Upvotes: 0
Views: 1836
Reputation: 523244
To put string into the pasteboard, use
[UIPasteboard generalPasteboard].string = @"some text";
To get selected text from the WebView, use -stringByEvaluatingJavaScriptFromString:
with appropriate Javascript.
Upvotes: 2