Shivam Sinha
Shivam Sinha

Reputation: 5150

TextInput placeHolder Alignment

What is the best way to align the placeholder text for TextInput component? I have already attempted to use the styles component as described below. There doesn't seem to be a property for this.

render() {
    return (
        <View style={styles.container}>
             <TextInput
                style={styles.textInput}
                onChangeText={(text) => this.setState({
                    username: text
                })}
                placeholder='Add Username'
             />
      </View>
    );
}

}

const styles = StyleSheet.create({
 container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
 },
 textInput: {
    height: 40,
    width: 200,
    justifyContent: 'center',
    alignItems: 'center',
    alignSelf: 'center',
    borderColor: 'gray',
    borderWidth: 1,
 }

});

Upvotes: 45

Views: 50866

Answers (4)

gpbaculio
gpbaculio

Reputation: 5968

set TextInput style padding:0 and adjust spacing accordingly

Upvotes: 1

amir behrouzi
amir behrouzi

Reputation: 155

if you doesnt give multiline property of textinput 'true'

place holder is always center of text input

you can give padding for example paddingTop

to style of textInput

to make distance between place holder and textinput

Upvotes: 3

Nguyễn Ph&#250;c
Nguyễn Ph&#250;c

Reputation: 293

Add textAlign={'center'} as a property to the TextInput component

Upvotes: 9

Daniel Basedow
Daniel Basedow

Reputation: 13396

Add textAlign: 'center' to your textInput style.

Upvotes: 58

Related Questions