UIWebView,只需在css中选择“实际”字体,而不仅仅是家庭?

Fat*_*tie 3 css uiwebview ios swift

在 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>
Run Code Online (Sandbox Code Playgroud)

这是已安装的 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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

帮助!

joe*_*ern 5

您必须在 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>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

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