我正在嘗試更改UIWebView
中的字體。 我嘗試用下面的代碼來改變字體。如何將JavaScript添加到iOS中的UIWebView?
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *cssPath = [path stringByAppendingPathComponent:@"test.css"];
if(!cssPath)
{
NSLog(@"NO");
}
NSString *js = [NSString stringWithFormat:@"var cssChild = document.createElement('link');"
"cssChild = 'text/css';"
"cssChild = 'stylesheet';"
"cssChild = '%@';", cssPath];
js = [NSString stringWithFormat:@"%@ document.getElementsByTagName('head')[0].appendChild(cssChild);", js];
[webViewOfInitial stringByEvaluatingJavaScriptFromString:js];
我將css文件添加到Internet的加載頁面的標題中。 我的css文件就是這樣的。
@font-face {
font-family: 'Zawgyi-One';
font-style: normal;
src: local('Zawgyi-One');
}
body {
font-family: 'Zawgyi-One';
}
但是,當我完成頁面加載時檢索HTML標記,我找不到我上面的css標記。 那麼我該如何將該css文件追加到UIWebView's
標題標籤的當前頁面? 還是有其他的教程UIWebView
字體更改?
謝謝。
什麼是htmlString? –
如果可以的話,請用靜態HTML頁面爲我的問題寫一個示例項目。我真的需要。請。 –
htmlstring是你的html內容..它可以是一個NSString或AN NSString直接指向一個html文件 –