ImageBackground es un componente que te permite usar una imagen como fondo, y sobre ella renderizar contenido como texto, botones, etc. Es muy útil para headers visuales, pantallas de bienvenida, etc.
import { View, Text, StyleSheet, ImageBackground } from 'react-native';
const image = require('./assets/goku.png');
const FondoConTexto = () => {
return (
<ImageBackground
source={image}
style={styles.fondo}
resizeMode="cover"
>
<View style={styles.contenido}>
<Text style={styles.titulo}>¡Bienvenido!</Text>
</View>
</ImageBackground>
);
};
const styles = StyleSheet.create({
fondo: {
flex: 1,
justifyContent: 'center',
alignItems: 'center', // Centra horizontalmente
width: '100%',
height: '100%',
},
contenido: {
backgroundColor: 'rgba(0,0,0,0.5)',
padding: 20,
borderRadius: 10,
alignItems: 'center',
},
titulo: {
color: '#fff',
fontSize: 28,
fontWeight: 'bold',
},
});
export default FondoConTexto; | Propiedad | Descripción |
|---|---|
source | Fuente de la imagen (local o remota). |
style | Estilo del contenedor. Debe tener width y height o flex. |
resizeMode | Cómo se ajusta la imagen: 'cover', 'contain', 'stretch', 'center', etc. |
imageStyle | Estilos específicos para la imagen de fondo (borde, borderRadius, etc). |
Puedes aplicar rgba() o backgroundColor con opacidad para oscurecer la imagen y mejorar la legibilidad del contenido encima.