私のアプリケーションでは、オンラインから読み込まれた webPage からフォントを変更する必要があります。
最初に CustomJava.js ファイルをオンライン ホスティングに保存し、そのファイルを使用して iOS アプリのフォントを変更します。
ここに私のコードのいくつかがあります。
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *js = [NSString stringWithFormat:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.src = 'http://www.gustohei.com/SYjs/customJava.js';"];
js = [NSString stringWithFormat:@"%@ document.getElementsByTagName('head')[0].appendChild(script);", js];
[self.webViewOfBrowser stringByEvaluatingJavaScriptFromString:js];
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}
それは問題なく、フォントを正しく変更します。
私の場合、その JS ファイルをドキュメント ディレクトリに保持し、そのファイルをドキュメント ディレクトリから使用したいと考えています。オンラインから使いたくない
だから私は次のコードを書きました。
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *jsPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"customJava.js"];
NSString *js = [NSString stringWithFormat:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.src ='%@'",jsPath];
js = [NSString stringWithFormat:@"%@ document.getElementsByTagName('head')[0].appendChild(script);", js];
[self.webViewOfBrowser stringByEvaluatingJavaScriptFromString:js];
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}
しかし、それはうまくいきません。どうやってするか?