React Native 中的 ImageBackground 组件的 imageRef 属性

返回上一级

React Native 中的 ImageBackground 组件的 imageRef 属性为 ImageBackground 组件的 背景图片 创建一个引用。

然后,我们就可以通过这个 图片引用 动态的更新 ImageBackground 组件的 背景图片 的属性

语法

<ImageBackground
  imageStyle={{width:300,height:169}}>
</ImageBackground>

导入模块

import { ImageBackground } from 'react-native'

属性说明

属性 类型 必填 平台
imageRef Ref Android,iOS

范例

下面的范例演示了如何使用 ImageBackground 组件的 imageRef 属性

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

export default class App extends Component{

  constructor(props) {
    super(props);
    this.imgRef = React.createRef();
  }

  render() {
    return (
      <View>
        <ImageBackground
          style={{width:300,height:169}} 
          source={{uri:'https://www.twle.cn/static/i/img1.jpg'}}
          imageRef={this.myRef}
          imageStyle={{width:300,height:169}}>
          <Text>简单教程简单编程</Text>
          <Text>https://www.twle.cn</Text>
        </ImageBackground>
      </View>
    );
  }
}

返回上一级

React Native 中文文档

关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.