反应本机不接受用Usefonts钩进口的字体
我将一些带有Expo cli的Usefonts导入了一些自定义字体文件,但是有一个错误的说法:
fontfamily“ Productsans”不是系统字体,尚未通过字体加载。loadasync
这是代码的
import { useFonts } from 'expo-font';
const FontScreen= () => {
const [customFonts] = useFonts({
ProductSans: '../../assets/fonts/ProductSansRegular.ttf',
ProductSansBold: '../../assets/fonts/ProductSansBold.ttf',
});
<Text style={{fontFamily: 'ProductSans' }}>Text</Text>
}
问题是什么?
I imported some custom font files with useFonts with expo cli, but there's an error saying,
fontFamily "ProductSans" is not a system font and has not been loaded through Font.loadAsync
Here's the code
import { useFonts } from 'expo-font';
const FontScreen= () => {
const [customFonts] = useFonts({
ProductSans: '../../assets/fonts/ProductSansRegular.ttf',
ProductSansBold: '../../assets/fonts/ProductSansBold.ttf',
});
<Text style={{fontFamily: 'ProductSans' }}>Text</Text>
}
What is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
usefonts()
挂钩工作类似:由于
customfonts
是一个布尔值,它描述了字体是否加载,因此仅在custic> custicfonts 是正确的。另外,请确保使用
需要
函数来正确加载它们:时将功能正确加载:
您还可以在
fontsloaded
是false:更多信息在这里。The
useFonts()
hook works like so:Since the
customFonts
is a boolean that describes if the fonts are loaded, you should only apply the font ifcustomFonts
is true. Also, make sure to surround your font paths with therequire
function to load them properly:You could also have the expo loading screen show while
fontsLoaded
is false:More info here.