ios - 在uiwebview中选择文本时如何禁用复制共享选项?但是选择文本应该可以
<p><p>我想限制用户在 <code>UIWebView</code> 中复制和共享文本。 </p>
<p>我使用的代码是</p>
<pre><code>- (void)viewDidLoad {
;
self.webview.delegate = self;
NSString *path = [ pathForResource:@"SampleHTML" ofType:@"html"];
NSString *htmlContent = ;
];
// Do any additional setup after loading the view, typically from a nib.
</code></pre>
<p>}</p>
<pre><code>-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
return NO;
else if (action == @selector(select:))
return YES;
return ;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您需要做的第一件事是添加带有 UIWEBVIEW 子类的新类。</p>
<p>将此代码粘贴到您类(class)的 .m 文件中。</p>
<pre><code>@implementation UIWebView (Additional)
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
BOOL superCanPerform = ;
if (superCanPerform) {
if (action == @selector(copy:) ||
action == @selector(paste:)||
action == @selector(cut:)||
action == @selector(_share:))
{
return false;
}
}
return superCanPerform;
}
</code></pre>
<p>试试这个,这将隐藏所有需要的子菜单。</p></p>
<p style="font-size: 20px;">关于ios - 在uiwebview中选择文本时如何禁用复制共享选项?但是选择文本应该可以,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37986733/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37986733/
</a>
</p>
页:
[1]