[英]How to change Custom Font in UIWebView?
I tried 我试过了
I loaded m.facebook.com into my UIWebView, which I'd like to change to a custom font. 我将m.facebook.com加载到我的UIWebView中,我想将其更改为自定义字体。 However, the font did not change.
但是,字体没有更改。 I believe the above answer is for static HTML Page.
我相信以上答案是针对静态HTML页面的。
I'm new to iOS, so a detailed explanation would be appreciated. 我是iOS的新手,所以不胜详细的解释。
The documentation is here, which is Safari CSS Reference 文档在这里,这是Safari CSS参考
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
. 好的,所以我们所做的基本上是声明为
NSString
。 We call it myDescriptionHTML
. 我们称其为
myDescriptionHTML
。 The string basically has HTML code/structure that, in a nutshell, changes the body font to helvetica. 基本上,该字符串具有HTML代码/结构,可以简单地将主体字体更改为helvetica。 And the
[NSNumber numberWithInt:kFieldFontSize], content]
basically specifies that the font size. [NSNumber numberWithInt:kFieldFontSize], content]
基本上指定了字体大小。 Then: 然后:
[webView loadHTMLString:myDescriptionHTML baseURL:nil];
Now our UIWebView
is calling the method loadHTMLString: baseURL:
现在,我们的
UIWebView
调用方法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. loadHTMLString:
带有一个具有HTML结构的参数, myDescriptionHTML
是完美的,我们只是声明要使用特定字体加载HTML页面。 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. 像图片之类的东西将需要
baseURL
参数,但是除非不需要您的字体/您已经创建了它,否则我们将不需要此参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.