/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from ‘react‘; import { Platform, StyleSheet, Text, View, TabBarios, StatusBar, } from ‘react-native‘; type Props = {}; export default class App extends Component<Props> { constructor(props){ super(props); this.state={ selectedTab:"图书" } } render() { return ( <TabBarIOS> <TabBarIOS.Item title="图书" //每次添加新图片都要重新run一下Xcode //下面一行是ES5的写法在ES6中无法使用 // icon={require("image!book_16")} //ES6中的写法为:icon={{uri:‘imageName‘}} icon={{uri:‘book_16‘}} selected={this.state.selectedTab==="图书"} onPress={()=>{ this.setState({ selectedTab:"图书" }) }}> <View style={{backgroundColor:‘green‘,flex:1}}></View> </TabBarIOS.Item> <TabBarIOS.Item title="电影" icon={{uri:‘movie_16‘}} selected={this.state.selectedTab==="电影"} onPress={()=>{ this.setState({ selectedTab:"电影" }) }}> <View style={{backgroundColor:‘skyblue‘,flex:1}}></View> </TabBarIOS.Item> </TabBarIOS> ); } }