图片的加载(非原文)
包括从网络、iOS(image.assets)和Android的Drawable文件夹中加载图片的方法
加载iOS项目中图片,图片在assets中<新加入图片之后一定要用Xcode重新编译项目>
render() {
return (
<View style={styles.container}>
<Text style={{marginTop: 20}}>加载本地图片</Text>
<Image source={require('./myImage/40@2x.png')} style={{width: 100, height: 100}}></Image>
<Text style={{marginTop: 10}}>加载网络图片</Text>
<Image source={{uri: 'https://www.baidu.com/img/bd_logo1.png'}} style={{width: 150, height: 70}}></Image>
<Text style={{marginTop: 10}}>加载iOS项目中图片,图片在assets中(新加入图片之后一定要用Xcode重新编译项目)</Text>
<Image source={{uri: 'banner.png'}} style={{width: 100, height: 40}} />
<Text style={{marginTop: 10}}>加载iOS项目中图片,图片在assets中</Text>
<Image source={require('image!banner')} style={{width: 300,height:100}}/>
<Text style={{marginTop: 10}}>加载iOS项目中图片,其他文件夹中</Text>
<Image source={{uri: 'mine_icon.png'}} style={{width: 100, height: 100}} />
<Text style={{marginTop: 10}}>加载android项目中drawable文件夹中的图片</Text>
<Image source={{uri: 'mine_icon'}} style={{width: 100, height: 100}} />
<Text style={{marginTop: 10}}>设置图片为背景</Text>
<Image source={require('./myImage/40@2x.png')} style={{width: 100, height: 100}}>
<Text style={{marginTop: 30}}>测试图片为背景</Text>
</Image>
</View>
);
}
网友评论