参考:
http://blog.csdn.net/wmmhwj/article/details/68483592 import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
ScrollView,
TabBarIOS } from 'react-native'; /*
* 在React Native 实现页面切换,提供两个组件: TabBarIOS 和TabBarIOS.Item
*
* 常用属性:
* selected: 是否选中了某个Tab
* title 标题
* barTintColor Tab栏的背景颜色
* icon 图标
* onPress 点击事件,当某个tab被选中时,需要改变组件的selected={true}设置
* 切换原理:点击tab时触发onPress方法,记录被点击tab的title,在通过title设置tab是否被选中(从而设置selected值 true/false)
*
*
* */ /*
*
* 导入textInput.js
* 导入loadimage.js
* 导入movieList.js movie.json
*
* */
var Page1 = require("./textInput");
var Page2 = require("./loadimage");
var Page3 = require("./movieList"); var LessionTabBarIOS = React.createClass({ getInitialState:function () {
return{
//用于记录显示的页面组件的title
tab:"Page1"//默认的
}
},
//TabBarIOS.Item 的onPress处理方法
select:function (tabName) {
this.setState({
tab:tabName
}) }, render:function () {
return(
<TabBarIOS style={{flex:1}}>
<TabBarIOS.Item
title="Page1"
icon={require("image!image1")}//图片直接放在了xcode的.asset 中
onPress={this.select.bind(this,"Page1")}
selected={this.state.tab==="Page1"}
>
{/*//页面组件*/}
<Page1></Page1>
</TabBarIOS.Item>
<TabBarIOS.Item
title="Page2"
//使用系统的图片
systemIcon="bookmarks"
onPress={this.select.bind(this,"Page2")}
selected={this.state.tab==="Page2"}
>
{/*//页面组件*/}
<Page2></Page2>
</TabBarIOS.Item>
<TabBarIOS.Item
title="Page3"
icon={require("image!image3")}//图片直接放在了xcode的.asset 中
onPress={this.select.bind(this,"Page3")}
selected={this.state.tab==="Page3"}
>
{/*//页面组件*/}
<Page3></Page3>
</TabBarIOS.Item>
</TabBarIOS>
);
} });
//////////-------ES6 语法-----////////////////////////////////////////////////////////////////////////////////////
/*导入组件*/

import OnePage from "./OnePage"
import TwoPage from "./TwoPage" class ThreePage extends Component{
render(){
return(
<View style={{backgroundColor:"red", flex:1}}>
<Text>hello</Text>
</View>
)
}
} export default class App extends Component<{}> {
constructor(props){
super(props);
this.state={
tab:"One"
}
      //注意:需要通过 bind() 来指定 this, 否则指定不明确,无法调用函数 or 也可以在调用的时候直接绑定
this.select = this.select.bind(this) }
select(tabTitle){
this.setState({
tab:tabTitle
})
} render() {
return (
<TabBarIOS style={{flex:1,alignItems:"flex-end"}}
> <TabBarIOS.Item
      title="Three"
      icon={require('./活动.png')}
      onPress={this.select.bind(this,'One')} //调用的时候,直接绑定, 并传参数
      seleted={this.state.tab==="Three"}> <View style={{backgroundColor:"red"}}>
<Text>Hello</Text>
</View> </TabBarIOS.Item> <TabBarIOS.Item title="Two" systemIcon="bookmarks" onPress={this.select} seleted={this.state.tab==="Two"}>
<TwoPage></TwoPage>
</TabBarIOS.Item> </TabBarIOS>
);
}
}
注意: 有时,tabBar已经显示, 而页面没有渲染出来, 检查页面的布局 flex:1

TabBarIOS的更多相关文章

  1. React Native 之TabBarIOS

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  2. React Native组件之ScrollView 和 StatusBar和TabBarIos

    React Native中的组件ScrollView类似于iOS中的UIScrollView,其基本的使用方法和熟悉如下: /** * Sample React Native App * https: ...

  3. React-Native 之 TabBarIOS

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  4. React Native 的组件之底部导航栏 TabBarIOS(一)

    import React,{Component}from 'react'; import { AppRegistry, StyleSheet, Text, View, TabBarIOS, } fro ...

  5. React Native常用组件之TabBarIOS、TabBarIOS.Item组件、Navigator组件、NavigatorIOS组件、React Navigation第三方

    以下内容为老版本React Native,faceBook已经有了新的导航组件,请移步其他博客参考>>[我是传送门] 参考资料:React Navigation  react-native ...

  6. ReactNative: 使用标签栏组件TabBarIOS组件

    一.简介 标签栏Tab的作用对于应用程序那是不言而喻的,它是应用程序中除了导航栏组件外的又一个核心组件,使用它可以实现页面的切换.RN提供了一个TabBarIOS组件来完成页面的切换(视图或者路由), ...

  7. React Native组件介绍

    1.React Native目前已有的组件 ActivityIndicatorIOS:标准的旋转进度轮; DatePickerIOS:日期选择器: Image:图片控件: ListView:列表控件: ...

  8. react-native-vector-icons的简单使用,图片,按钮,标签视图,导航条

    ICONS是可以直接使用图片名, 就能加载图片的三方,使用很方便, 你不需要在工程文件夹里塞各种图片, 节省很多空间,下面就来看看怎么使用吧! 1. 首先打开terminal进入到我们的工程文件夹下, ...

  9. React Native之 Navigator与NavigatorIOS使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

随机推荐

  1. Oracle表格字段采用sequence进行自增长时,采用Dbutils进行insert或update数据时的处理技巧

    // 定义插入记录的方法 public Teacher insert(String name, String gender, Double score) { // 获得连接 Connection co ...

  2. SqlSugar Asp.Net 高性能ORM框架

    SqlSugar从去年到现在已经一年了,版本从1.0升到了现在的2.4.1 ,这是一个稳定版本 ,有数家公司已经项目上线,在这里我将SqlSugar的功能重新整理成一篇新的贴子,希望大家喜欢. 公司团 ...

  3. ProxyPattern(23种设计模式之一)

    设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...

  4. dedecms开启报错调试

    位置:/include/common.inc.php //error_reporting(E_ALL); error_reporting(E_ALL || ~E_NOTICE); 替换成 error_ ...

  5. Mac os安装DVWA环境教程

    Mac os安装DVWA环境教程 1.尽管Mac自带Apache和php 事实上Mac和WIN都用XAMPP一键化安装比较方便 2.解压DVWA-master 改名为dvwa移动到XAMPP的目录 3 ...

  6. Memcached在Windows下的配置和使用(转)

    出处:http://www.cnblogs.com/sunniest/p/4154209.html Memcached学习笔记---- 安装和配置 首先,下载Memcached相关文件. 打开控制台, ...

  7. Qt编译,imp_CommandLineToArgvW@8问题

    Tested msvc2013. The linker can not find _imp_CommandLineToArgvW@8. It's in shell32.lib. I see qtmai ...

  8. jquery 常用工具方法

    inArray(value, array [, fromIndex ])方法类似于原生javascript的indexOf()方法,没有找到匹配元素时它返回-1.如果数组第一个元素匹配参数,那么$.i ...

  9. 实用的chrome插件

      有人说Chrome是世界上最好的浏览器,当然也会有不赞同.但不论怎样,工具而已,何必限制,任何一个用好了都能迅速提高我们的效率,不过还是推荐Chrome. 自然问题就变成:“为什么要用Chrome ...

  10. [LeetCode 题解]: Merge k Sorted Lists

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 题 ...