Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change placeholder textSize in react-native

In my TextInput I want to change the size of the font of placeHolder, I tried like this:

<TextInput
    style={styles.email}
    value={this.state.email} 
    placeholder="Email"
    placeholderTextColor="red"
    //placeholderTextSize = 20px
    onChange={this.handleEmailChange.bind(this)}
    onBlur={this.onBlur.bind(this)}/>

when I wrote like this color is working for me but size is not working, can any one give me suggestions how to change the size of placeholder Text, any help much appreciated

like image 867
Hussian Shaik Avatar asked Nov 04 '15 07:11

Hussian Shaik


People also ask

How do I change the placeholder font size in React Native?

To change font family for TextInput placeholder in React Native, we can set the fontFamily style of the TextInput . to set the fontFamily property to 'courier' to render the text inputted in the TextInput with Courier.

How do I change placeholder text in React Native?

To change the styling of TextInput placeholder in React Native, we can set the placeholderTextColor prop. to set the placeholderTextColor to 'red' to set the placeholder color of the input to red.

How do you make a placeholder in React Native?

Basically Placeholder provides hints or message about that particular TextInput Component, To add PlaceHolder text in TextInput Component, you need to specify placeholder=" Enter Your First Name" Props inside the TextInput Component.


Video Answer


2 Answers

TextInput component can be created like this.

<TextInput
value={value}
style={value ? styles.input : styles.placeholder}
placeholderTextColor="white"
{...props}/>
like image 140
Hakan Saglam Avatar answered Oct 16 '22 06:10

Hakan Saglam


There's no way (as far as I remember) to directly change the font size of only the placeholder, since when you change the fontSize using styles, you're changing both, the input fontSize as well as placeholder fontSize. However, there is a way tho...

const [ text, setText ] = useState<string>('');

and then use the state to check whether the input field is empty or not. If it is empty, then change the fontSize as:

{ fontSize: text ? 18 : 12 }

However, it is important to note that even tho this method works, but the delay caused by the re-render is, of course, noticable.

like image 22
dev404 Avatar answered Oct 16 '22 07:10

dev404