2016-04-04 66 views
0

我想知道如何去插入圖像到這?JavaScript - 添加圖像:反應本機XCode

我也想知道這是JavaScript實現的CSS還是實現在JavaScript中的CSS?

它是自動生成的陣營本土作爲默認的應用程序啓動器包,我們剛開的基本知識交手...

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


class VLDB extends Component { 
    render() { 
    return (
     <View style={styles.container}> 
     <Text style = {styles.welcome}> 
     VLDB SQL Cheat Sheet! 
     </Text> 
     <Text style={styles.welcome}> 
      Welcome to the SQL Cheat Sheet! 
     </Text> 
     <Text style={styles.instructions}> 
      To get started, edit index.ios.js 
     </Text> 
     <Text style={styles.instructions}> 
      Press Cmd+R to reload,{'\n'} 
      Cmd+D or shake for dev menu 
     </Text> 
     </View> 
    ); 
    } 
} 


const styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    justifyContent: 'center', 
    alignItems: 'center', 
    backgroundColor: '#F5FCFF', 
    }, 
    welcome: { 
    fontSize: 20, 
    textAlign: 'center', 
    margin: 10, 
    }, 
    instructions: { 
    textAlign: 'center', 
    color: '#333333', 
    marginBottom: 5, 
    }, 
}); 


AppRegistry.registerComponent('VLDB',() => VLDB); 

乾杯,盧克。

回答

1

將圖像添加到這一點,首先需要在圖像成分

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

然後添加的圖像爲通過引用本地捆綁圖像或像這樣的遠程圖像中the documentation描述進口。 ..

class VLDB extends Component { 
    render() { 
    return (
     <View style={styles.container}> 
     <Image 
      style={styles.icon} 
      source={require('./myIcon.png')} 
      /> 
     <Image 
      style={styles.logo} 
      source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} 
      /> 
     <Text style = {styles.welcome}> 
     VLDB SQL Cheat Sheet! 
     </Text> 
     <Text style={styles.welcome}> 
      Welcome to the SQL Cheat Sheet! 
     </Text> 
     <Text style={styles.instructions}> 
      To get started, edit index.ios.js 
     </Text> 
     <Text style={styles.instructions}> 
      Press Cmd+R to reload,{'\n'} 
      Cmd+D or shake for dev menu 
     </Text> 
     </View> 
    ); 
    } 
} 
+0

我怎麼能張貼代碼回到你身邊,我使用的是第一種方法,需要(「./ button.png」)} –

+0

以下是錯誤:我收到: 無法解決模塊.button.png來回m /Users/lcharlton/VLDB/index.ios.js:無法在其模塊映射或/Users/lcharlton/VLDB/button.png及其父目錄下的任何node_modules目錄中找到此模塊 –

+1

因此,「./ button.png「路徑意味着button.png文件與調用它的文件存在於同一個目錄中(在你的案例中是index.ios.js)。那是哪裏? –