[英]why can't I use custom fonts in react native
even tho I did everything correctly my react app still dosen't change the font.即使我做的一切都正确,我的反应应用程序仍然没有改变字体。
First I added首先我添加
module.exports = {
assets: ['./assets/fonts']
}
to react-native.config.js至 react-native.config.js
then I created a folder in the assets folder and named it fonts and pasted all the fonts there然后我在资产文件夹中创建了一个文件夹并将其命名为 fonts 并将所有 fonts 粘贴在那里
then I used this commmand npx react-native-asset
然后我使用了这个命令npx react-native-asset
after that I added fontFamily: Poppins-Regular
to the stylesheets and it dosen't work!之后我在样式表中添加了fontFamily: Poppins-Regular
并且它不起作用!
Please someone tell me what did I do wrong!请有人告诉我我做错了什么!
Here is my code:这是我的代码:
import React from 'react';
import {Image, StyleSheet, Text, View, ImageBackground, Dimensions } from 'react-native';
const width_screen = Dimensions.get('window').width;
const hight_screen = Dimensions.get('window').height;
const card_size = {
width:614,
height:285,
}
let card_hight = 0;
if (width_screen < 614)
card_hight = ((screen.width - 50) * card_size.height) / card_size.width;
else
card_hight = 285
const Card = () => {
return (
<ImageBackground
source={require('../assets/card1.png')}
style={styles.card}>
<View style={styles.card}>
<Text>
<img style={styles.image} src={require('../assets/user4.png')}/>
<Text style={styles.cardNameText}>{'Bahez'}</Text>
<Text style={styles.balance}>100<Text style={styles.usdt}>USDT</Text></Text>
</Text>
<img style={styles.settings} src={require('../assets/settings.png')}/>
<Text style={styles.inviteCode}>Invite Code : 1225346</Text>
</View>
</ImageBackground>
);
}
export default Card;
const styles = StyleSheet.create({
card : {
width: "100%",
height : card_hight,
maxHeight : 285,
maxWidth: 614,
},
test : {
backgroundColor : 'red',
},
cardNameText : {
marginTop : 25,
position : 'absolute',
color : 'white',
fontSize : 22,
fontWeight : 500,
},
balance :{
fontFamily : 'Poppins-Regular',
position: 'absolute',
top : 10,
right: 20,
color : 'white',
fontWeight : 800,
fontSize : 25,
},
inviteCode : {
position : 'absolute',
bottom : 20,
left : 25,
color : 'white',
fontWeight : 500,
},
settings : {
width : 20,
height : 20,
position: 'absolute',
bottom : 20,
right: 25,
},
usdt : {
padding : 3,
paddingTop : 15,
fontSize : 13,
},
image: {
padding : 20,
width: 40,
height: 40,
}
});
Can you try to change the name of the font to this:您可以尝试将字体名称更改为:
balance :{
fontFamily : 'Poppins',
position: 'absolute',
top : 10,
right: 20,
color : 'white',
fontSize : 25,
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.