Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place a text over image in react native?

Tags:

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 image

like image 761
Linu Sherin Avatar asked Mar 13 '18 07:03

Linu Sherin


People also ask

How do you set text on above the image in React Native?

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', }, });

How do you overlay images in React Native?

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.

How do I add a tag to a photo in React Native?

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.


2 Answers

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>

like image 50
Clad Clad Avatar answered Sep 22 '22 10:09

Clad Clad


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> 
like image 43
jaideep rawat Avatar answered Sep 26 '22 10:09

jaideep rawat