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