1
私はNibに2つのuiwebviewを追加し、同じhtmlをドキュメント辞書にロードします。webViewDidFinishLoadは、1つのビュー内の2つのuiwebviewsでは機能しません。
それは二回webViewDidFinishLoadになりますが、一つだけのWebViewのスタイルを変更...
おかげで、ここに私のコードは次のとおりです。私は
- (void)viewDidLoad{
NSString *_pagesPath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/chapter5.htm"];
web1.delegate = self;
[web1 loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:_pagesPath]]];
web2.delegate = self;
[web2 loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:_pagesPath]]];
}
- (void) webViewDidFinishLoad:(UIWebView*)webView{
NSString *varMySheet = @"var mySheet = document.styleSheets[0];";
NSString *addCSSRule = @"function addCSSRule(selector, newRule) {"
"if (mySheet.addRule) {"
"mySheet.addRule(selector, newRule);" // For Internet Explorer
"} else {"
"ruleIndex = mySheet.cssRules.length;"
"mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" // For Firefox, Chrome, etc.
"}"
"}";
NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;line-height:3.5')"];
NSString *insertRule3 = [NSString stringWithFormat:@"addCSSRule('body', 'background:#e0d9ca;')"];
[webView stringByEvaluatingJavaScriptFromString:varMySheet];
[webView stringByEvaluatingJavaScriptFromString:addCSSRule];
[webView stringByEvaluatingJavaScriptFromString:insertRule2];
[webView stringByEvaluatingJavaScriptFromString:insertRule3];
}
おかげで、私はここで解決策を持ってます。http://double-slash.net/2010/10/18/using-multiple-ios -uiwebview-objects / – user1114574