且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

禁用UIWebView中的用户选择

更新时间:2023-11-30 15:48:58

以下是禁用选择的几种方法:

Here are a few ways to disable selection:

<style type="text/css">
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none; /* Disable selection/copy in UIWebView */
}
</style>



以编程方式加载以下Javascript代码:



Programmatically load the following Javascript code:

NSString * jsCallBack = @"window.getSelection().removeAllRanges();";    
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];



禁用复制/粘贴用户菜单:



Disable the Copy / Paste user menu:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{    
    if (action == @selector(copy:) ||
        action == @selector(paste:)||
        action == @selector(cut:)) 
    {
        return _copyCutAndPasteEnabled;
    }
    return [super canPerformAction:action withSender:sender];
}