【问题标题】:UIWebView, simply select "actual" font in css, not just family?UIWebView,只需在css中选择“实际”字体,而不仅仅是家庭?
【发布时间】:2016-07-07 23:41:20
【问题描述】:

在 iOS 中,我使用 UIWebView 加载这个短文本文件 然后在 UIWebView 中显示它。 (loadHTMLString)

<html><head><style type='text/css'>
body
{
font-family:'Source Sans Pro';
font-size:12pt;
}
html { -webkit-text-size-adjust:none; }
</style></head>
<body leftmargin=0 topmargin=0>
example text...
</body></html>

这里是安装的 12 个“实际”字体名称 (print(UIFont.fontNamesForFamilyName("Source Sans Pro")))

[“SourceSansPro-BoldIt”、“SourceSansPro-SemiboldIt”、“SourceSansPro-ExtraLight”、“SourceSansPro-Semibold”、“SourceSansPro-Bold”、“SourceSansPro-Black”、“SourceSansPro-Regular”、“SourceSansPro-Light ", "SourceSansPro-BlackIt", "SourceSansPro-It", "SourceSansPro-ExtraLightIt", "SourceSansPro-LightIt"]

现在在 UIWebView 中

body
{
font-family:'Source Sans Pro';
font-size:12pt;
}

效果很好;出现常规的Source Sans Pro 字体。

但是。很简单,我到底怎么告诉 css 使用“ExtraLight”、“BlackIt”等等?

如何在 12 种字体中选择特定的一种???

救命!

【问题讨论】:

    标签: ios css swift uiwebview


    【解决方案1】:

    您必须在 CSS 中使用实际的字体名称:

    <html>
        <head>
            <style type='text/css'>
                body {
                    margin: 30px;
                    font-family: 'SourceSansPro-Regular';
                    font-size: 12pt;
                }
                h1 {
                    font-family: 'SourceSansPro-Black';
                    font-size: 16pt;
                    font-weight: normal
                }
                .light {
                    font-family: 'SourceSansPro-ExtraLight';
                }
            </style>
        </head>
        <body>
            <h1>Header</h1>
            <p>Normal Text</p>
            <p class="light">Light Text</p>
        </body>
    </html>
    

    附带说明:当您使用提供“真实”粗体字体的字体时,最好删除“人工”粗体字体粗细,因为它会使已经粗体的字体更加粗体,看起来确实很难看。 (这就是我将font-weight: normal 添加到h1 选择器的原因)

    【讨论】:

    • 它在 UIWebView 中。
    • 你的 HTML/CSS 现在看起来怎么样了?
    • 感谢一百万!发送了一个赏金。 @乔恩
    • @JoeBlow 谢谢,很高兴我能帮上忙!
    猜你喜欢
    • 2017-03-19
    • 2011-04-11
    • 2014-09-15
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多