【问题标题】:How to make a UIWebView show its text with a custom font?如何使 UIWebView 使用自定义字体显示其文本?
【发布时间】:2010-09-27 21:57:33
【问题描述】:

看起来 UIWebView 中的字体是否默认为某种“Times New Roman”。我想我必须弄清楚苹果为 [UIFont systemFontOfSize:15] 使用什么字体......还是有一些智能的方法可以做到这一点?

【问题讨论】:

  • 我认为你需要通过 CSS 来实现,iPhone 的默认字体是 Verdana。这不是 Times New Roman 的典型网络字体。
  • 不,不是。系统字体为 iPhone 到 iPhone 3GS 的 Helvetica 和 iPhone 4 的 Helvetica Neue。

标签: iphone uiwebview


【解决方案1】:

如何在 UIWebView 中插入文本?假设您正在设置 HTML,您可以通过完整的 CSS、内联 CSS 或不推荐使用的字体标签来更改字体。

<html>
    <head>
        <style>
        BODY { font-family: 'Times New Roman'; font-size: 15px; }
        </style>
    </head>
    <body>
        Here is some text
    </body>
</html>

当然要适当调整样式和大小。

【讨论】:

  • 太棒了!谢谢!为了让不理解这一点的人更清楚,我从@JavaCoderEx 中添加了我的答案
【解决方案2】:
[myWebView loadHTMLString:[NSString stringWithFormat:@"<html><head><style>BODY { font-family: 'Arial-Bold'; font-size: 16px; }</style></head><body>%@</body></html>",htmlBodyString] baseURL:nil];

【讨论】:

    猜你喜欢
    • 2012-06-19
    • 2012-05-16
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    相关资源
    最近更新 更多