React Native组件之Switch和Picker和Slide
React Native组件Switch类似于iOS中的UISwitch;组件Slide类似于iOS中UIslider,组件Picker类似于iOS的UIPickerView。他们的使用方法和相关属性如下:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* 周少停 2016-09-28
* Switch 开关组件 Picker 选择器 和slide 进度条
*/ import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Switch,
Picker,
Slider
} from 'react-native'; class Project extends Component {
// 构造方法 相当于ES5的getInitialState方法
constructor(props) {
super(props);
// 初始状态
this.state = {
isOn:false,
pickerLabel:'苹果',
slideNum:0
};
} render() {
return (
<View style={styles.container}>
{/*--------------------------Switch-------------------------------*/}
<Switch
// disabled={true}//是否可以响应,默认为false,true是无法点击
onTintColor='blue' //开启时的背景颜色
thumbTintColor='yellow' //开关上原形按钮的颜色
tintColor='black' //关闭时背景颜色
onValueChange={() => this.setState({isOn: !this.state.isOn})} //当状态值发生变化值回调
value={this.state.isOn == true}//默认状态
/>
{/*--------------------------Picker-------------------------------*/}
<Picker style={{width:100,height:100}}
selectedValue = {this.state.pickerLabel}
onValueChange = {(e) => this.setState({pickerLabel:e})}>
<Picker.Item label="苹果" value="apple" />
<Picker.Item label="iPhone" value="手机" />
<Picker.Item label="苹果1" value="apple1" />
<Picker.Item label="iPhone1" value="手机1" />
<Picker.Item label="苹果2" value="apple2" />
<Picker.Item label="iPhone2" value="手机2" />
<Picker.Item label="苹果3" value="apple3" />
<Picker.Item label="iPhone3" value="手机3" />
</Picker>
{/*--------------------------Slide-------------------------------*/}
<Slider
// {...this.pops} //取到所有的该属性
// disabled = {true} //是否可滑动
// trackImage = {require('./img/1.jpg')} 滑道背景图片
// maximumTrackImage = {require('./img/2.jpg')} //滑道右侧侧背景图片
// minimumTrackImage = {require('./img/3.jpg')}//滑道左侧背景图片
// value = {10} //滑块的初始位置
minimumValue = {0} //最小之
maximumValue = {100} //最大值
step = {2} //步长,在minimumValue和maximumValue之间
maximumTrackTintColor = 'red' //滑道右侧的滑道颜色
minimumTrackTintColor = 'yellow' //滑道左侧的滑道颜色
onSlidingComplete = {(e)=>this.slideDone(e)} //停止滑动时调用,可以把当前值传过去
onValueChange = {(e)=>this.setState({slideNum:e})} //滑动时就调用,可以把当前值传过去
style={{marginTop:200,width:200}} />
<Text>Slide当前值:{this.state.slideNum}</Text>
</View>
);
}
slideDone(e){
alert(e);
}
} const styles = StyleSheet.create({
container: {
marginTop:30,
alignItems:'center'
}
}); AppRegistry.registerComponent('Project', () => Project);
完整源码下载:https://github.com/pheromone/React-Native-1
React Native组件之Switch和Picker和Slide的更多相关文章
- React Native组件之Text
React Native组件之Text相当于iOS中的UILabel. 其基本属性如下: /** * Sample React Native App * https://github.com/face ...
- React Native 组件之TextInput
React Native 组件之TextInput类似于iOS中的UITextView或者UITextField,是作为一个文字输入的组件,下面的TextInput的用法和相关属性. /** * Sa ...
- beeshell —— 开源的 React Native 组件库
介绍 beeshell 是一个 React Native 应用的基础组件库,基于 0.53.3 版本,提供一整套开箱即用的高质量组件,包含 JavaScript(以下简称 JS)组件和复合组件(包含 ...
- react native组件的生命周期
react native组件的生命周期 一.当页面第一次加载时,会依次调用: constructor() componentWillMount(): 这个函数调用时机是在组件创建,并初始化了状态之后, ...
- react native组件的创建
react native组件的创建 react文件加载顺序: react项目启动后,先加载index.js.在index.js中可以指向首页. import { AppRegistry } from ...
- React Native组件(三)Text组件解析
相关文章 React Native探索系列 React Native组件系列 前言 此前介绍了最基本的View组件,接下来就是最常用的Text组件,对于Text组件的一些常用属性,这篇文章会给出简单的 ...
- React Native组件(二)View组件解析
相关文章 React Native探索系列 React Native组件系列 前言 了解了RN的组件的生命周期后,我们接着来学习RN的具体的组件.View组件是最基本的组件,也是首先要掌握的组件,这一 ...
- Android React Native组件的生命周期及回调函数
熟悉android的童鞋应该都清楚,android是有生命周期的,其很多组件也是有生命周期.今天小编和大家分享的React Native组件的生命周期,还不了解的童鞋,赶紧来围观吧 在android开 ...
- React Native组件解析(二)之Text
React Native组件解析(二)之Text 1. 概述 Text组件对应于iOS的UILabel,Android的TextView,用来显示文本.但是Text组件的内部使用的并不是flexbox ...
随机推荐
- 远程读取json数据并写入数据库
参考:http://www.jb51.net/article/39937.htm $curlPost = 'a=1&b=2';//模拟POST数据$ch = curl_init();curl_ ...
- HttpWebRequest调用WebAPI
private void button1_Click(object sender, EventArgs e) { string ss= HttpPost("http://localhost: ...
- SQL Server书籍整理
1.<Microsoft SQL Server企业级平台管理实践>徐海蔚2.<SQL Server 2005 Performance Tuning性能调校>胡百敬3.<M ...
- 。Java注意事项
- python成长之路【第五篇】:python字符编码
在2.7环境中我们要写上这一行#-*- coding:utf-8 -*- 为什么我们要加这一行呢?这一样的意思是置顶编码类型为utf-8编码! 首先在看这个问题之前,咱们是否曾想过一个问题? 为什么我 ...
- iOS开发之滤镜的使用技巧(CoreImage)
一.滤镜的内容和效果是比较多并且复杂的 ,学习滤镜需要技巧 如下: 两个输出语句解决滤镜的属性选择问题: 1.查询效果分类中包含什么效果按住command 点击CIFilter 进入接口文件 找到第1 ...
- shell编程—— EOF
在shell编程中,”EOF“通常与”<<“结合使 用,“<<EOF“表示后续的输入作为子命令或子shell的输入,直到遇到”EOF“,再次返回到主调shell,可将其理解为分 ...
- solr 6.1 服务端 tomcat 搭建及调用
一.下载 apache solr6.1.0 最新版本zip,解压缩生成一个solr6.1.0文件夹 二.安装 1.在d:/projects下新建一个solr 2.把solr6.1.0/server/s ...
- apache开启.htaccess
1 . 如何让的本地APACHE开启.htaccess 如何让的本地APACHE开启.htaccess呢?其实只要简朴修改一下apache的httpd.conf设置就让APACHE.htaccess了 ...
- centos7.0 64位系统 安装PHP 支持 nginx
1 安装PHP所需要的扩展 yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl cur ...