0

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~

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
bluej3
  • 11
  • 1
  • 5

1 Answers1

2

To put string into the pasteboard, use

[UIPasteboard generalPasteboard].string = @"some text";

To get selected text from the WebView, use -stringByEvaluatingJavaScriptFromString: with appropriate Javascript.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • You are "my God" ^0^. I see briliant light in your answer. i will checking now~~~ Thank you so so so very much. (i have suffer from this problem while 5 days) ps. please pardon me my poor english. (i'm korean) – bluej3 Feb 21 '10 at 11:06