Engr.Aftab Ufaq
Engr.Aftab Ufaq

Reputation: 6272

How to add custom fonts in React Native

I am using react native custom fonts and there is an issue with that. 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 fontsenter image description here

image with custom fonts

note: I have checked it with multiple fonts and have same issue.

Upvotes: 0

Views: 473

Answers (2)

user18654575
user18654575

Reputation:

use includeFontPadding attribute, it will remove the default space

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

Upvotes: 0

Michael Bahl
Michael Bahl

Reputation: 3649

Try if the prop includeFontPadding or lineHeight remove the spacing.

<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.

Upvotes: 1

Related Questions