zoukankan      html  css  js  c++  java
  • 样式

    所有的核心组件都接受名为style的属性。这些样式名基本上是遵循了web上的CSS的命名,只是按照JS的语法要求使用了驼峰命名法,例如将background-color改为backgroundColor

    style属性可以是一个普通的JavaScript对象。这是最简单的用法,因而在示例代码中很常见。你还可以传入一个数组——在数组中位置居后的样式对象比居前的优先级更高,这样你可以间接实现样式的继承。

    实际开发中组件的样式会越来越复杂,我们建议使用StyleSheet.create来集中定义组件的样式。

    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);
  • 相关阅读:
    [BZOJ3043]IncDec Sequence
    【NOIP2015】字串
    [NOIP]2016天天爱跑步
    【NOIP2015】运输计划
    [poj3565]Ants
    【ZOJ2760】How Many Shortest Path
    [POJ3281] Dining
    P1077摆花
    校内测之zay与银临 (day2)
    P1880石子合并
  • 原文地址:https://www.cnblogs.com/dragonh/p/6210620.html
Copyright © 2011-2022 走看看