Lylys
Lylys

Reputation: 57

How to define an image as Background? (React Native)

I can't define this image as background.

How to make this image become a background on which I can put text?

import React, { Component } from 'react';
import { Text, View, StyleSheet, Image } from 'react-native';

export default class Youtube extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.paragraph}>
        Hello
        </Text>
        <Image style={styles.logo} source={require("../assets/images/ici.jpg")}/>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    alignItems: 'center',
    justifyContent: 'center',
  },
  paragraph: {
    margin: 24,
    marginTop: 0,
    fontSize: 24,
    fontWeight: 'bold',
    textAlign: 'center',
    color: '#34495e',
  },
  logo: {
    backgroundColor: "#056ecf",
    height: 660,
    width: 660,
  }
});

How to make this image become a background on which I can put text?

Upvotes: 0

Views: 127

Answers (1)

Petrogad
Petrogad

Reputation: 4423

You want to use ImageBackground to nest components under it.

return (
  <ImageBackground source={require("../assets/images/ici.jpg")} style={{width: '100%', height: '100%'}}>
      <Text>
         Hello
      </Text>
  </ImageBackground>
);

Upvotes: 1

Related Questions