问题
Is there a way to add custom font in React Native in Atom editor and not using Xcode?
回答1:
There is an easier way of doing things through command line using rnpm
. It adds fonts to both android and ios. Place the font you want to add to a suitable location inside your project directory. In your package.json just add the following:
...
"rnpm": {
"assets": ["path/to/your/font/directory"]
},
...
Then from command line do: rnpm link
you can now happily use your fonts in your app.
Note: you have to have rnpm installed for this to work.
Just do npm install -g rnpm
Here is the documentation: https://github.com/rnpm/rnpm#advanced-usage
回答2:
The way without edit package.json is:
Install in your proyect react-native-vector-icons (
npm install --save react-native-vector-icons
).Move the fonts into
node_modules/react-native-vector-icons/Fonts
.run
react-native link
.run
react-native run-ios
The problem is that the name of the fonts is different than the file name. The way to show all names of the installed fonts is modify AppDelegate.m
and put the loop:
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"%@", fontName);
}
}
For icons fonts the name is the same.
回答3:
Not Possible to add Custom Font iOS .
You are using Xcode then add Font in native app
- Copy your font file into resources
- Add a key to your Info.plist file called UIAppFonts. ("Fonts provided by application)Make this key an array
- For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array
来源:https://stackoverflow.com/questions/38564125/how-do-i-add-custom-font-in-react-native-not-using-xcode