Au Ris Au Ris - 3 months ago 31
iOS Question

How to change UIWebView default font

What font does UIWebView use by default? I would like to be able to change that. But I don't want to do it in the html string, instead I want to have something like:

[webView setFont:[UIFont fontWithName:@"GothamRounded-Bold" size:14]


is there such property or some other way?

Answer

Just prefix a <font face> tag to your string before loading into the webView.

NSString *body = [plist objectForKey:@"foo"];
NSString *htmlString = 
    [NSString stringWithFormat:@"<font face='GothamRounded-Bold' size='3'>%@", body];
[webView loadHTMLString:htmlString baseURL:nil];
Comments