Example

示例

import React, { Component } from 'react';
import {Switch,StyleSheet,} from 'react-native';
export class pageComponent extends Component {
    constructor(props){
        super(props);
        this.state={
            swicthValue: false
        }
    }
    onChange =(value)=>{
        this.setState({
            value: value
        })
    };
    render(){
        return(
            <Switch style={styles.switch}
                    onTintColor={'#ff00ff'}
                    tintColor={'#00ffff'}
                    value={this.state.swicthValue}
                    onValueChange={(value)=> {
                        //修改value的值,不然无法改变状态
                        this.setState({
                            swicthValue: value
                        })
                    }}
                    testID={'one'}
                    thumbTintColor={'#ffff00'}/>
        )
    }
}
const styles = StyleSheet.create({
    switch: {
        marginTop: 100,
    },
});
该文件修订时间: 2021-01-14 15:02:10

results matching ""

    No results matching ""