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