【发布时间】:2020-03-16 12:44:56
【问题描述】:
我正在努力加载我的字体,PressStart2P。它是来自谷歌字体的字体。 . .已多次执行以下步骤,以确保我没有马虎。根据所有迹象,该字体应该在 react native 应用程序中可用。
- 在我的项目目录的根目录下创建了 assets 文件夹
- 在 assets 文件夹中创建字体文件夹并将字体文件放置在其中...与 PostScript 名称所指示的完全一样,并且使用了 .otf 和 .ttf 版本的字体。
- 在 package.json 中,指定自定义字体所在的位置:
"rnpm": {
"assets": [
"./assets/fonts/"
]
},
- 在我的终端中,输入 npx react-native 链接
- 在 App.js 中添加了我的字体
作为参考,这里是整个 App.js 文件:
import React, { Component } from 'react';
import { Text, View , TouchableOpacity} from 'react-native';
export default class HelloWorldApp extends Component {
render() {
return (
<View style={{ backgroundColor:'#e9ffc945',flex: 1,
justifyContent: "center", alignItems: "center" }}>
<Text style={{fontSize:26, color: "#85321b45",
fontFamily: "PressStart2P"}}>Allah'u'Abha :)</Text>
<TouchableOpacity
style={{
backgroundColor:'#a4a6fc19',
padding: 95,
borderRadius: 19,
}}
>
<Text
style={{
color: "white",
fontSize: 20
}}
>
</Text>
</TouchableOpacity>
</View>
);
}
}
此外,我已经在 xcode 的项目目标中签入了我的副本包资源...文件就在那里。有什么想法吗?
【问题讨论】:
-
您在使用 PressStart2P-Regular 吗?
-
stackoverflow.com/a/57253751/8932231**请参考这个答案**
标签: reactjs react-native