ReactNative样式

1. 直接写死在控件的方法:

//由于在jsx中,style后面是json对象,所以要写两个{}
<View style={{backgroundColor:'#333333',alignItems:'flex-end'}}>
<Text>哈哈</Text>
</View>
</View>


2. 一般不推荐上面的写法,而是将样式写在如下面的代码中:

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

使用样式时如下代码:

//通过json对象方法访问样式
<View style={styles.container}>
</View>

多个样式采用数组的方式:

//通过json对象方法访问样式
<View style={[styles.container,styles.welcome]}>
</View>



原文出处:http://www.malaoshi.top/show_1C78JTR0NKS.html