I tried
I loaded m.facebook.com into my UIWebView, which I'd like to change to a custom font. However, the font did not change. I believe the above answer is for static HTML Page.
I'm new to iOS, so a detailed explanation would be appreciated.
I tried
I loaded m.facebook.com into my UIWebView, which I'd like to change to a custom font. However, the font did not change. I believe the above answer is for static HTML Page.
I'm new to iOS, so a detailed explanation would be appreciated.
The documentation is here, which is Safari CSS Reference
You can also try this:
NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-family: \"%@\"; font-size: %@;}\n"
"</style> \n"
"</head> \n"
"<body>%@</body> \n"
"</html>", @"helvetica", [NSNumber numberWithInt:kFieldFontSize], content];
Ok, so what we did was basically declared an NSString
. We call it myDescriptionHTML
. The string basically has HTML code/structure that, in a nutshell, changes the body font to helvetica. And the [NSNumber numberWithInt:kFieldFontSize], content]
basically specifies that the font size.
Then:
[webView loadHTMLString:myDescriptionHTML baseURL:nil];
Now our UIWebView
is calling the method loadHTMLString: baseURL:
The loadHTMLString:
takes a parameter that has a HTML structure, myDescriptionHTML
is perfect, we just declared that to load the HTML page with a specific font. baseURL
parameter will be needed for something like an image, but we won't need that, unless your font is not supported/you created it.