How to change the font size in UIWebview

11,550

Put this code in your webViewDidFinishLoad delegate method:

-(void)webViewDidFinishLoad:(UIWebView *)webView1{

int fontSize = 20;
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'", fontSize];
[webView1 stringByEvaluatingJavaScriptFromString:jsString];
[jsString release];

}

Hope it helps ;)

Update: For developers who enabled ARC, you should ignore adding:

[jsString release];

Share:
11,550
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a UIWebView that loadHTMLString from an array.

    I need this webView to change the font size dynamically

    here is how i fill my WebView:

    [webView loadHTMLString:[NSString stringWithFormat:@"%@<p class=\"paragraph\"  style=\"float: right\"  >%@</p>",css,[[ contentArray objectAtIndex:0] valueForKey:@"content"]]   baseURL:nil ];
    
  • Admin
    Admin about 11 years
    Thank you^99 times, thats worked for me
  • coder
    coder over 7 years
    This is not working anymore for iOS 10.1.1, is there any alternative?