A period of time need to modify WebView background color, on StackOverflow search for a long time no results found, Baidu Search, all kinds of reprint, all kinds of pit Dad, search out all only font size and font color, page background did not see, I publish method, hope can help more people
In the WebView delegate callback method-webviewdidfinishload: (uiwebview*) WebView; write the last statement
Font size
[WebView stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname_r (' body ') [0]. style.webkittextsizeadjust= ' 330% ' "];
Font Color
[WebView stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname_r (' body ') [0]. Style.webkittextfillcolor= ' Gray ' "];
Page background color
[WebView stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname_r (' body ') [0].style.background= ' #2E2E2E ' "];
Before the method written in the init, how can not, originally had to write in the delegate AH (above is correct)
-(void) Initwebview
{
if (!self.mywebview) {
Self.mywebview = [[UIWebView alloc] initWithFrame:self.view.bounds];
}
Self.myWebView.delegate = self;
Self.myWebView.opaque = NO; Do not set this value the page background is always white
Self.myWebView.backgroundColor = [Uicolor Clearcolor];
Self.myWebView.scalesPageToFit = NO; Prevent users from scaling pages
Self.myWebView.dataDetectorTypes = uidatadetectortypephonenumber| Uidatadetectortypelink;
self.myWebView.scrollView.pagingEnabled = YES;
Self.myWebView.scrollView.contentInset = uiedgeinsetsmake (0, 0, 0, 0);
Self.myWebView.autoresizingMask = uiviewautoresizingflexiblewidth| Uiviewautoresizingflexibleheight;
[Self.view AddSubview:self.myWebView];
NSString *jsstring = [[NSString alloc] initwithformat:@ "document.body.style.fontsize=%f;document.body.style.color=% @ ", 16.0,[color webcolorstring]];
[Self.mywebview stringbyevaluatingjavascriptfromstring:jsstring];
}
IOS ios_uiwebview font size, font color, background color--learning notes in Lan Yi education