How to vertically place a text over image in react native? I found this doc. But i can't do like that , I can't add text
tag as a child component of Image
tag.I've tried like the below.
<Card> <CardSection> <View style={styles.container}> <Image source={require('../Images/4.jpg')} style={styles.imageStyl} /> <Text style={styles.userStyle}> {this.props.cat.name} </Text> </View> </CardSection> </Card> const styles= StyleSheet.create({ container:{ flex: 1, alignItems: 'stretch', justifyContent: 'center', }, imageStyl: { flexGrow:1, width:"100%", height:200, alignItems: 'center', justifyContent:'center', }, userStyle:{ fontSize:18, color:'black', fontWeight:'bold', textAlign: 'center' }, });
How to place the text to the center of image?Getting something like this
create({ container: { flex: 1, }, coverImage: { width: '100%', height: 200, }, textView: { position: 'absolute', justifyContent: 'center', alignItems: 'center', top: 0, left: 0, right: 0, bottom: 0, }, imageText: { fontSize: 20, color: 'white', fontWeight: 'bold', }, });
To add a transparent overlay in React Native, we can use the ImageBackground component. to add an ImageBackground with the source set to an object with the uri of the background image. And we add the backgroundImage style that sets opacity to 0.3 to add a transparent overlay over the image.
Adding Image Let us create a new folder img inside the src folder. We will add our image (myImage. png) inside this folder. We will show images on the home screen.
You have to use in the "css" position:'absolute'
And then place your text using the css properties (like top, bottom, right, left)
React Native absolute positioning horizontal centre
Wrap the child you want centered in a View and make the View absolute.
<View style={{position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center'}}> <Text>Centered text</Text> </View>
use this:
<ImageBackground source={require('background image path')} style={{width: '100%', height: '100%'}}> <View style={{position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center'}}> <Text>Centered text</Text> </View> </ImageBackground>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With