一、hello world
//要使用标签,第一步必须导入import React, { Component } from 'react';import { Text, View,Button} from 'react-native';export default class App extends Component {render() {return (<View><Text>Hello, world!</Text><Buttoncolor="#ff2d51"title="btn"/></View>);}}
二、Image
//网络图片<Image source={{uri:"xxx"}}>//Tips:图片相关的资源一定要夹样式width,height
//本地图片<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 (
} } const styles = StyleSheet.create({ container:{ backgroundColor:”red”, width:200, height:200 }, txt:{ color:”blue” }, bg:{ backgroundColor:”#fff” } })
<a name="eTJc5"></a>### 四、Dimensions```javascriptimport { Dimensions } from 'react-native';const { width, height,scale} =Dimensions.get('window');
五、布局
Tip: react-native中默认view就是flex布局
export default class App extends Component {render() {return (<View style={styles.container}><View style={styles.child}></View><View style={styles.child}></View><View style={styles.child}></View></View>);}}const styles = StyleSheet.create({container: {width:400,height:400,backgroundColor:"red",flexDirection:"row",justifyContent:"space-around",alignItems:"center"},child:{width:100,height:100,backgroundColor:"blue"}})
六、transform
transform:[{translate:[-50,-50]}]// transform:[{translateX:-50},{translateY:-50}]
七、border属性
borderColor:边框颜色borderWidth:边框宽度borderRadius:边框圆角半径borderStyle:边框样式'solid'实线,'dotted'点,'dashed'虚线
八、自定义按钮
- 文档
```javascript
跳过
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” } }) ```
