一、hello world

  1. //要使用标签,第一步必须导入
  2. import React, { Component } from 'react';
  3. import { Text, View,Button} from 'react-native';
  4. export default class App extends Component {
  5. render() {
  6. return (
  7. <View>
  8. <Text>Hello, world!</Text>
  9. <Button
  10. color="#ff2d51"
  11. title="btn"/>
  12. </View>
  13. );
  14. }
  15. }

二、Image

  1. //网络图片
  2. <Image source={{uri:"xxx"}}>
  3. //Tips:图片相关的资源一定要夹样式width,height
  1. //本地图片
  2. <Image source={require('./assets/bg.jpg')}/>

三、样式

  • View样式 ```javascript import React, { Component } from ‘react’; import { Text, View,StyleSheet} from ‘react-native’;

export default class App extends Component { render() { return ( //给多个style hello );

} } const styles = StyleSheet.create({ container:{ backgroundColor:”red”, width:200, height:200 }, txt:{ color:”blue” }, bg:{ backgroundColor:”#fff” } })

  1. <a name="eTJc5"></a>
  2. ### 四、Dimensions
  3. ```javascript
  4. import { Dimensions } from 'react-native';
  5. const { width, height,scale} =Dimensions.get('window');

五、布局

Tip: react-native中默认view就是flex布局

  1. export default class App extends Component {
  2. render() {
  3. return (
  4. <View style={styles.container}>
  5. <View style={styles.child}></View>
  6. <View style={styles.child}></View>
  7. <View style={styles.child}></View>
  8. </View>
  9. );
  10. }
  11. }
  12. const styles = StyleSheet.create({
  13. container: {
  14. width:400,
  15. height:400,
  16. backgroundColor:"red",
  17. flexDirection:"row",
  18. justifyContent:"space-around",
  19. alignItems:"center"
  20. },
  21. child:{
  22. width:100,
  23. height:100,
  24. backgroundColor:"blue"
  25. }
  26. })

六、transform

  1. transform:[{translate:[-50,-50]}]
  2. // transform:[{translateX:-50},{translateY:-50}]

七、border属性

  1. borderColor:边框颜色
  2. borderWidth:边框宽度
  3. borderRadius:边框圆角半径
  4. borderStyle:边框样式'solid'实线,'dotted'点,'dashed'虚线

八、自定义按钮

const styles = StyleSheet.create({ btn: { width:50, height:30, backgroundColor:”#333”, borderColor:”#fff”, borderWidth:1, borderRadius:20, borderStyle:”solid”, justifyContent: ‘center’, alignItems: ‘center’, }, text:{ color:”#fff” } }) ```