在React Native iOS的图像顶部渲染透明背景文本框

前端之家收集整理的这篇文章主要介绍了在React Native iOS的图像顶部渲染透明背景文本框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的React Native测试中,我试图在图像的顶部渲染一个带有白色文本的块。但是,我的图像顶部有一个黑色块,其中有白色文字。不是我预期的如何渲染具有透明背景的文本块?

当前结果

渲染功能

  1. render: function(){
  2. return (
  3. <View style={styles.container}>
  4. <Image
  5. style={styles.backdrop}
  6. source={{uri: 'https://unsplash.com/photos/JWiMShWiF14/download'}}>
  7. <Text style={styles.headline}>Headline</Text>
  8. </Image>
  9. </View>
  10. );
  11. )

样式表功能

  1. var styles = StyleSheet.create({
  2. container: {
  3. flex: 1,justifyContent: 'flex-start',alignItems: 'center',backgroundColor: '#000000',width: 320
  4. },backdrop: {
  5. paddingTop: 60,width: 320,height: 120
  6. },headline: {
  7. fontSize: 20,textAlign: 'center',backgroundColor: 'rgba(0,0)',color: 'white'
  8. }
  9. });
您可以通过在图像中添加视图来完成此操作:
  1. render: function(){
  2. return (
  3. <View style={styles.container}>
  4. <Image
  5. style={styles.backdrop}
  6. source={{uri: 'https://unsplash.com/photos/JWiMShWiF14/download'}}>
  7. <View style={styles.backdropView}>
  8. <Text style={styles.headline}>Headline</Text>
  9. </View>
  10. </Image>
  11. </View>
  12. );
  13. )

样式表功能

  1. var styles = StyleSheet.create({
  2. container: {
  3. flex: 1,backdropView: {
  4. height: 120,},color: 'white'
  5. }
  6. });

猜你在找的React相关文章