先上效果動態(tài)圖
代碼附上:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TabBarIOS
} from 'react-native';
var test5 = React.createClass({
//設(shè)置初始值
getInitialState(){
return{
//默認(rèn)選擇的item
selectTabBarItem:'home',
}
},
render() {
return (
<View style={styles.container}>
<View style={styles.headStyle}>
<Text style={{color:'white'}}>Tab選項(xiàng)卡</Text>
</View>
<TabBarIOS
barTintColor='black'
//tintColor='purple'
>
{/*第一*/}
<TabBarIOS.Item
systemIcon="contacts"
badge="3"
title="張三"
selected={this.state.selectTabBarItem == 'home'}
onPress = {()=>{this.setState({selectTabBarItem:'home'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'red'}] }>
<Text style={{color:'white'}}>首頁</Text>
</View>
</TabBarIOS.Item>
{/*第2*/}
<TabBarIOS.Item
systemIcon="bookmarks"
selected={this.state.selectTabBarItem == 'second'}
onPress = {()=>{this.setState({selectTabBarItem:'second'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'blue'}]}>
<Text style={{color:'white'}}>2頁</Text>
</View>
</TabBarIOS.Item>
{/*第3*/}
<TabBarIOS.Item
systemIcon="downloads"
selected={this.state.selectTabBarItem == 'three'}
onPress = {()=>{this.setState({selectTabBarItem:'three'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'yellow'}]}>
<Text style={{color:'white'}}>3頁</Text>
</View>
</TabBarIOS.Item>
{/*第4*/}
<TabBarIOS.Item
systemIcon="search"
selected={this.state.selectTabBarItem == 'four'}
onPress = {()=>{this.setState({selectTabBarItem:'four'})}}
>
<View style={[styles.commonViewStyle,{backgroundColor:'purple'}]}>
<Text style={{color:'white'}}>4頁</Text>
</View>
</TabBarIOS.Item>
</TabBarIOS>
</View>
);
}
})
const styles = StyleSheet.create({
container: {
flex:1,
backgroundColor: '#F5FCFF',
},
headStyle:{
height:64,
backgroundColor:'black',
justifyContent:'center',
alignItems:'center'
},
commonViewStyle:{
flex:1,
justifyContent:'center',
alignItems:'center'
}
});
AppRegistry.registerComponent('test5', () => test5);