Reputation: 5150
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
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
Reputation: 293
Add textAlign={'center'}
as a property to the TextInput component
Upvotes: 9