005_ReactNative: Style

2016-08-21  本文已影响0人  莫_名

(问渠那得清如许,为有源头活水来。 双手奉上RN官网)

style属性用于设置样式.写法类似于web上的CSS(层叠样式表:Cascading Style Sheets).


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

class LotsOfStyles extends Component {
  render() {
    return (
      <View>
        //指定单个样式
        <Text style={styles.red}>just red</Text>
        <Text style={styles.bigblue}>just bigblue</Text>
         //指定一组样式,对于相同的部分,以最后的为准
        <Text style={[styles.bigblue, styles.red]}>bigblue, then red</Text>
        <Text style={[styles.red, styles.bigblue]}>red, then bigblue</Text>
      </View>
    );
  }
}

//定义样式列表
const styles = StyleSheet.create({
  bigblue: {
    color: 'blue',
    fontWeight: 'bold',
    fontSize: 30,
  },
  red: {
    color: 'red',
  },
});

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

上一篇下一篇

猜你喜欢

热点阅读