IOS ios_uiwebview font size, font color, background color--learning notes in Lan Yi education

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.