如何在React-Native中使用Google可变字体?

5

我正在尝试在React Native中使用Google定制字体,但出现了问题,我从Google下载了OpenSans字体,并正确地将其配置到了react-native中。

字体文件名称为:OpenSans-VariableFont_wdth,wght.ttf

我正在尝试像这样使用它:

{
fontSize: 18,
fontFamily:"OpenSans-Bold"
},

但是我遇到了这样的问题:未识别的字体系列“OpenSans-Bold”。但是如果我像这样给出OpenSans-Regular,它就能正常工作。

我该如何使用这个文件OpenSans-VariableFont_wdth,wght.ttf


对我来说,我总是使用 Expo 字体,并在 app.js 中加载它。https://docs.expo.dev/guides/using-custom-fonts 但你也可以将你的 .ttf 资源链接到 iOS 或 Android。 - ucup
1个回答

0

这是我自己的设置方式

<style>@font-face {font-family: "OpenSans-Regular";src: url("OpenSans-VariableFont_wght.ttf");}</style>

and for iOS don't forget this to your webview

src={ {html:xxxx, baseUrl: '' }}
originWhitelist={['*']}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接