打开Xcode,选择Open a project or file
找到RN工程下的ios下的.xcodeproj文件并打开
打开之后,界面像下面这样
点击右键,在菜单中选择New Group,起名Resources
选择Resources,右键菜单中选择Add File to “xxx”
找到RN项目下,node_modules下,你要引用的字体,选择字体所在的文件夹,点击添加
xCode界面上,会看到刚添加的字体们
确认Build Phases下的Copy Bundle Resources下有那些字体
打开RN工程下的ios下项目名下的info.plist,粘贴字体名字
我引用的字体名字如下,每个人情况不一样,但是格式都是一样的
<key>UIAppFonts</key>
<array>
<string>AntDesign.ttf</string>
<string>Entypo.ttf</string>
<string>EvilIcons.ttf</string>
<string>Feather.ttf</string>
<string>FontAwesome.ttf</string>
<string>FontAwesome5_Brands.ttf</string>
<string>FontAwesome5_Regular.ttf</string>
<string>FontAwesome5_Solid.ttf</string>
<string>Foundation.ttf</string>
<string>Ionicons.ttf</string>
<string>MaterialIcons.ttf</string>
<string>MaterialCommunityIcons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Octicons.ttf</string>
<string>Zocial.ttf</string>
<string>Fontisto.ttf</string>
</array>
回到xCode,确认Fonts provided by application下是否有你加的这些字体。
在RN工程根目录下,新建react-native.config.js,粘贴如下配置
module.exports = {
dependencies: {
'react-native-vector-icons': {
platforms: {
ios: null,
},
},
},
};
记得保存文件
RN工程下ios下执行这几步,然后字体就好用了
- 进入ios文件夹
- run
pod install - run
rm -rf build - run
cd .. - run
yarn ios