admin管理员组文章数量:1420907
I'm trying to add custom TTF font to my react native project, I've followed articles :
1) I've create a folder in my root and putted vincHand.ttf in that :
projectName/assets/fonts/vincHand.ttf
2) I've executed this mand :
react-native link
And then I've checked and font has transferred to android path right
3) I've uninstalled the app in the Genymotion and again I've executed this mand :
react-native run-android
But after fontFamily: 'vincHand' that text is shown with default font ...
Consider it, I've downloaded this font from here :
.font
I'm trying to add custom TTF font to my react native project, I've followed articles :
1) I've create a folder in my root and putted vincHand.ttf in that :
projectName/assets/fonts/vincHand.ttf
2) I've executed this mand :
react-native link
And then I've checked and font has transferred to android path right
3) I've uninstalled the app in the Genymotion and again I've executed this mand :
react-native run-android
But after fontFamily: 'vincHand' that text is shown with default font ...
Consider it, I've downloaded this font from here :
https://www.dafont./vinchand.font
Share Improve this question edited Aug 15, 2018 at 4:52 asked Aug 15, 2018 at 4:36 user10179106user101791064 Answers
Reset to default 0You should ensure two things:
The first thing is you already defined this in package.json
"rnpm": {
"assets": [
"./assets/fonts/"
]
},
React-Native will automatically copy the font to android/app/src/main/assets/fonts
The second thing is defining this in Info.plist
<key>UIAppFonts</key>
<array>
<string>vincHand.ttf</string>
</array>
Then run react-native link
For usage case:
const styles = StyleSheet.create({
wele: {
fontFamily: "vincHand",
fontSize: 30,
textAlign: "center",
margin: 10
}
});
Good luck!
- Create assets folder in the root folder of your project.
- Create fonts folder inside the assets folder.
- Paste all the fonts inside the fonts folder.
- Add the below mentioned code inside the package.json file.
- Run the below mentioned Command
react-native link
- Fonts will get installed on both the platforms(IOS and Android).
"rnpm": { "assets": [ "./assets/fonts/" ] },
Both ios & android (without expo):
1 - create a folder called "assets", inside it create "fonts" folder and put all your ttf files inside it.
2 - create a file in the root called: react-native.config.js
and put insdie it :
module.exports = {
project: {
ios: {},
android: {}
},
assets: ['./assets/fonts']
};
3 - run this mand: npx react-native link
I know this is an old thread, but just in case someone finds it useful.
I followed HDT's instructions, including kouhadi's hint about using react-native.config.js
, but it didn't work for me (I'm using React Native v0.75.2
).
What did work was running the following mand after setting up the fonts:
npx react-native-asset
This mand re-links the assets, and after running it, my custom fonts worked as expected.
Note: This might be necessary for more recent versions of React Native (like v0.75.x
), as the auto-linking may not always pick up the fonts without this manual step.
本文标签: javascriptHow can I add custom TTF font in my React Native projectStack Overflow
版权声明:本文标题:javascript - How can I add custom TTF font in my React Native project? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745346500a2654508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论