React native学习第九章:图片


import React,{Component} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image
} from 'react-native';

class RNHighScores extends React.Component {
  render() {
    var contents = this.props["scores"].map(
      score => <Text key={score.name}>{score.name}:{score.value}{"\n"}</Text>
    );

    return (

      <View style={styles.container}>
        <Text style={styles.highScoresTitle}>
          2048 High Scores!
        </Text>
        <Text style={styles.scores}>
          {contents}
        </Text>


          <Image source={require('./img/icon_manage.png')}/>
          <Image source={{uri:'mainView_imv_ruoyou'}} style={{width:300,height:200}}/>
          <Image source={{uri:'https://facebook.github.io/react/img/logo_og.png'}} style={{width:200,height:200}}/>
          <Image source={require('./img/icon_manage.png')}>
            <Text>inside</Text>
          </Image>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#FFFFFF',
  },
  highScoresTitle: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  scores: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

// 整体js模块的名称
AppRegistry.registerComponent('RNHighScores', () => RNHighScores);































  <Image source={require('./img/icon_manage.png')}/>访问根路径下的图片,大小就是图片大小

  <Image source={{uri:'mainView_imv_ruoyou'}} style={{width:300,height:200}}/>访问项目Assets下的图片,大小必须申明

  <Image source={{uri:'https://facebook.github.io/react/img/logo_og.png'}} style={{width:200,height:200}}/>访问网络图片,大小需声明

<Image source={require('./img/icon_manage.png')}>
            <Text>inside</Text>
 </Image> 背景图

遇到的问题:图片显示不出来warning :Native component for “RCTImageView” does not exist

在podfile里面

 

target ‘PlayGame’ do

  # 'node_modules'目录一般位于根目录中
  # 但是如果你的结构不同,那你就要根据实际路径修改下面的`:path`
  pod 'React', :path => ‘/Users/macmini/Desktop/PlayGame/node_modules/react-native', :subspecs => [
    'Core',
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # 这个模块是用于调试功能的
    'RCTImage',
    # 在这里继续添加你所需要的模块
  ]
  # 如果你的RN版本 >= 0.42.0,请加入下面这行
  pod "Yoga", :path => “/Users/macmini/Desktop/PlayGame/node_modules/react-native/ReactCommon/yoga"

end

进入根目录,pod update一下,再运行就好了




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值