我怎么能使用本机的android和ios使用相同的自定义字体 [英] How can i use same custom fonts for both android and ios using react native
问题描述
我使用react native来处理ios和android的相同代码。现在,在我的项目中,我想为两者使用自定义字体。我知道如何为ios应用自定义字体但是那些相同的字体如何申请android呢?
I am working with the same code for both ios and android using react native. Now in my project I want to use custom fonts for both. I know how to apply custom fonts for ios but those same fonts how to apply for android also?
//新样本
我在
下添加了自定义字体样本/ android / app / src / main / assets / fonts / gillsans-italic.ttf I
应用了这个gillsans-italic CustomFontTest组件中的.ttf字体
如下所示
I added the custom font under sample/android/app/src/main/assets/fonts/gillsans-italic.ttf I applied this gillsans-italic.ttf font in CustomFontTest component like below
var CustomFontTest = React.createClass({
render:function(){
return (<View><Text style={styles.customFont}>CustomFont</Text></View>)
}
})
var styles = StyleSheet.create({
customFont:{
fontFamily:'gillsans-italic',
fontSize:14,
color:'#efefef'
}
})
推荐答案
将你的字体放在 android / app / src / main / assets / fonts
下。
他们必须根据字体系列名称命名。以下是支持的内容:
They must be named according to the font family name. Here is what is supported:
{{fontName}}。otf
{{fontName}} _ bold.otf
{{fontName}} _ bold_italic.otf
{{fontName}}.otf
{{fontName}}_bold.otf
{{fontName}}_bold_italic.otf
您可以将.otf替换为.ttf。 {{fontName}}
是您传递给组件的 style
属性的名称。
You can replace .otf with .ttf. The {{fontName}}
is the name you pass through to the style
property of a component.
这篇关于我怎么能使用本机的android和ios使用相同的自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!