【问题标题】:How can force copy selected text ? [iPhone]如何强制复制选定的文本? [苹果手机]
【发布时间】:2010-02-21 09:17:12
【问题描述】:

嗨~我有一个问题。 ^^

如何在 UIWebView(或 UITextView)上获取“选定文本”?

我想复制“选定的文本”而不​​复制/粘贴弹出视图。

1) 我删除了...复制/粘贴视图。 (成功了~)

UIMenuController *theMenu = [UIMenuController sharedMenuController];
[theMenu setMenuVisible:NO];
[theMenu update];

2.强制复制“选定文本”(失败)

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

如何在 canPerformAction 中复制文本。 ?

我要复制“选定文本”的原因只是为了通过更改颜色和字体来装饰文本。

谢谢你~

【问题讨论】:

    标签: iphone cocoa-touch copy-paste uipasteboard


    【解决方案1】:

    要将字符串放入粘贴板,请使用

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

    要从 WebView 中获取选定的文本,请使用 -stringByEvaluatingJavaScriptFromString:appropriate Javascript

    【讨论】:

    • 你是“我的上帝”^0^。我在你的回答中看到了灿烂的光芒。我现在会检查~~~ 非常感谢你。 (我在 5 天内遇到了这个问题) ps。请原谅我糟糕的英语。 (我是韩国人)
    猜你喜欢
    • 1970-01-01
    • 2011-04-23
    • 2011-01-27
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 2011-08-19
    相关资源
    最近更新 更多