我想在用户点击粗体,斜体时更改网页视图的内容,并在html字符串中对应的更改值下划线。我正在实现这个代码。它改变了视图但我们如何获得html中的更改值。我是iOS的新手。请帮助。非常感谢。
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
NSLog(@"canperfom Action:called");
NSLog(@"canPerformAction: called");
NSLog(@" action %@", NSStringFromSelector(action));
if (action == @selector(_showTextStyleOptions:)) {
NSLog(@"hello");
return NO;
}
if (action==@selector(toggleBoldface:)) {
NSLog(@"bye");
return NO;
}
return [super canPerformAction:action withSender:sender];
}
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
[theWebView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];
NSString *js = @"var styleNode = document.createElement('style');\n"
"styleNode.type = 'text/css';\n"
"var styleText = document.createTextNode('a {-webkit-tap-highlight-color:rgba(0,0,0,0)}');\n"
"styleNode.appendChild(styleText);\n"
"document.getElementsByTagName('head')[0].appendChild(styleNode);\n";
[theWebView stringByEvaluatingJavaScriptFromString:js];
}
NSString * tempMailBodyString = [NSString stringWithFormat:@“%@”,myTextView.text]; NSString * htmlString = [Globals replaceRegex:@“(?i)\ b((?:[az] [\ w - ] + :(?:/ {1,3} | [a-z0-9%])| WWW \ d {0,3} | [A-Z0-9 \ - ] + [AZ] {2,4} /)[] [](?:[^ \ S()<>] + | \(([^ \ S()<>] + |(\([^ \ S()<>] + \))) \))+(:\((? [^ \ S()<>] + |(\([^ \ S()<>] + \))!) \)| [^ \ s`()\ [\ ] {};:'\“。,<>?«»”“'']))”:tempMailBodyString:[NSString stringWithFormat:@“$ 1 $ 2”]];
答案 0 :(得分:0)
我认为你可以做的是,当点击一个按钮时,你会像在webViewDidFinishLoad中那样注入javascript并将样式添加到html:他们你必须将修改后的html加载到webView。但我认为你正在使用stringByEvaluatingJavaScriptFromString:错误。它只返回修改后的HTML,您必须将其加载回webview
returnedHTMLString = [theWebView stringByEvaluatingJavaScriptFromString:js];
[theWebView loadHTMLString:returnedHTMLString baseURL:nil];