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 ...
随机推荐
- 浙江理工2015.12校赛-G Jug Hard
Jug Hard Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1172 Solved: 180 Description You have two e ...
- [poj2777] Count Color (线段树 + 位运算) (水题)
发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...
- [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:实现基本的CRUD功能
英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with Entity Framework 6 Code First using MVC 5 系列 ...
- [Golang] 一个简易代理池
晚上写了一个代理池,就是在一个代理网站上爬取代理ip和端口以及测试是否可用.接下来可能考虑扩展成一个比较大的 golang实现的代理池. 简易版代码: package main import ( &q ...
- C#:Hashtable和Dictionary
Dictionary<TKey, TValue> () Hashtable() 第一.存储的数据类型 Hashtable不是泛型的,不是类型安全的:Dictionary是泛型的, ...
- html之meta详解
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...
- 浅谈HTTP协议(下)
下面来讲响应消息.响应消息也分为响应起始行.响应头部.CRLF.响应主体. 响应起始行包括协议版本.响应状态码.原因短句.这里的重点就是响应状态码,它一共分为5类,状态码准确的说是一个三位数. 1xx ...
- Django1.9开发博客(9)- 用户认证
你应该注意到了一点,当你去新建.修改和删除文章的时候并不需要登录,这样的话任何浏览网站的用户都能随时修改和删除我的文章.这个可不是我想要的! 编辑和删除的认证 我们需要保护post_new, post ...
- Centos 安装 neo4j
This is experimental and not considered safe for production. You have been warned. Please note that ...
- 【python】selenium+python自动化测试环境搭建
参考资料: http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html http://www.easonhan.info/python/20 ...