How to center Text in ReactNative both in horizontal and vertical?
I have an example application in rnplay.org where justifyContent=\"center\" and
Horizontal and Vertical center alignment
<View style={{flex: 1, justifyContent: 'center',alignItems: 'center'}}>
<Text> Example Test </Text>
</View>
first add in parent view flex:1, justifyContent: 'center', alignItems: 'center'
then in text add textAlign:'center'
this is a example for Horizontal and Vertical alignment simultaneously
<View style={{width: 200, flexDirection: 'row',alignItems: 'center'}}>
<Text style={{width: '100%',textAlign: 'center'}} />
</View>
The following property can be used: {{alignItems: 'center'}}
<View style={{alignItems: 'center'}}>
<Text> Hello i'm centered text</Text>
</View>
used
textalign:center
at the view
Wherever you have Text
component in your page just you need to set style of the Text
component.
<Text style={{ textAlign: 'center' }}> Text here </Text>
you don't need to add any other styling property, this is spectacular magic it will set you text in center of the your UI.