3

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 ];

1 Answers1

13

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];

Mutawe
  • 6,464
  • 3
  • 47
  • 90