微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

在我的React Native测试中,我试图在图像的顶部渲染一个带有白色文本的块。但是,我的图像顶部有一个黑色块,其中有白色文字。不是我预期的如何渲染具有透明背景的文本块?

当前结果

渲染功能

render: function(){
  return (
    <View style={styles.container}>
      <Image 
        style={styles.backdrop} 
        source={{uri: 'https://unsplash.com/photos/JWimshWiF14/download'}}>
          <Text style={styles.headline}>Headline</Text>
      </Image>
    </View>
  );
)

样式表功能

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

样式表功能

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

原文地址:https://www.jb51.cc/react/301767.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐