Expo / React-native 在 Android 和 IOS 之间更改字体
Expo / React-native change fonts between Android and IOS
我想知道如何为 IOS 和 Android 使用不同的字体,
我只有 1 个索引文件。(App.js)
我的代码适用于 IOS:
<Text style={{fontFamily: 'AppleSDGothicNeo-Thin'}}>Hello!</Text>
但是当我在 Android 上打开应用程序时,我看到了标准字体(Arial?)
我试过这样的事情:
<Text style={{fontFamily:'Roboto', fontFamily:'AppleSDGothicNeo-Thin'>Hello!</Text>
但这只是给我一个找不到字体的错误。
您可以使用来自 React Native 的 Platform 组件在您的样式中使用条件
import { Platform } from 'react-native';
<Text style={{fontFamily: (Platform.OS === 'ios') ? 'AppleSDGothicNeo-Thin' : 'Roboto'}}>Hello!</Text>
还要确保字体导入良好。
否则按以下步骤导入它们。
1 - 将要使用的字体放在项目内的目录中。例如在 ./assets/fonts/
2 - 在 package.json 中添加以下行:
“rnpm”: {
“assets”: [“./assets/fonts”]
}
3 - 运行 在终端中:
$ react-native link
我想知道如何为 IOS 和 Android 使用不同的字体, 我只有 1 个索引文件。(App.js)
我的代码适用于 IOS:
<Text style={{fontFamily: 'AppleSDGothicNeo-Thin'}}>Hello!</Text>
但是当我在 Android 上打开应用程序时,我看到了标准字体(Arial?)
我试过这样的事情:
<Text style={{fontFamily:'Roboto', fontFamily:'AppleSDGothicNeo-Thin'>Hello!</Text>
但这只是给我一个找不到字体的错误。
您可以使用来自 React Native 的 Platform 组件在您的样式中使用条件
import { Platform } from 'react-native';
<Text style={{fontFamily: (Platform.OS === 'ios') ? 'AppleSDGothicNeo-Thin' : 'Roboto'}}>Hello!</Text>
还要确保字体导入良好。
否则按以下步骤导入它们。
1 - 将要使用的字体放在项目内的目录中。例如在 ./assets/fonts/
2 - 在 package.json 中添加以下行:
“rnpm”: {
“assets”: [“./assets/fonts”]
}
3 - 运行 在终端中:
$ react-native link