简体   繁体   English

react-native 使用自定义 fonts

[英]react-native using custom fonts

I am using react native custom fonts and there is an issue with that.我正在使用 react native custom fonts并且存在问题。 with default the text is on center and when I use a Font then text has not on center.默认情况下,文本居中,当我使用字体时,文本不居中。 here is code.这是代码。

<TextInput 
    style={{
       height:40, 
       width:width-10, 
       margin:5, 
       backgroundColor:"#eee",
       borderRadius:5,
       paddingLeft:20,
       fontFamily:FONTS.medium  // if I comment this line then placeholder and text input is on center.
     }}
     placeholder="Search Here"
/>

Image with default fonts默认图像 fonts 在此处输入图像描述

带有自定义字体的图像

note: I have checked it with multiple fonts and have same issue.注意:我已经用多个 fonts 检查过它并且有同样的问题。

Try if the prop includeFontPadding or lineHeight remove the spacing.尝试使用includeFontPaddinglineHeight移除间距。

<Text
  style={{
        backgroundColor: 'red', 
        //lineHeight: 92, 
        fontSize: 24,  
        color: '#000000', 
        fontFamily: 'Roboto-Regular', 
        includeFontPadding: false}}>
        Search Here
</Text>

If this don't work check the font itself has a spacing.如果这不起作用,请检查字体本身是否有间距。 Open the font file *.ttf and check if the the text has a big spacing.打开字体文件*.ttf,检查文字是否有大间距。

use includeFontPadding attribute, it will remove the default space使用 includeFontPadding 属性,它将删除默认空间

<Text  style={{
     includeFontPadding: false
   }}>
     Search Here
</Text>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM