React Native 的组件之底部导航栏 TabBarIOS(一)
2024-08-23 02:25:45
import React,{Component}from 'react';
import {
AppRegistry, StyleSheet,
Text,
View,
TabBarIOS,
} from 'react-native';
import History from './History'
class TabBarIOSDemo extends Component {
constructor(props){
super(props);
this.state={
selectedTab: '发现',
notifCount: 0,
presses: 0,
};
}
//进行渲染页面内容
_renderContent(color: string, pageText: string, num: number) {
return (
<View style={[styles.tabContent, {backgroundColor: color}]}>
<Text style={styles.tabText}>{pageText}</Text> </View>
);
}
render() {
return (
<View style={{flex:1}}> <TabBarIOS
style={{flex:1,alignItems:"flex-end"}}
tintColor="green"/*被选中状态颜色图片和文字*/
barTintColor="#000">
<TabBarIOS.Item
title="主页"
icon={require('./img/1.png')}
selected={this.state.selectedTab === '主页'}
onPress={() => {
this.setState({
selectedTab: '主页',
});
}}
>
{this._renderContent('#414A8C', 'one')}
</TabBarIOS.Item>
<TabBarIOS.Item
title="发现"
icon={require('./img/2.png')}
selected={this.state.selectedTab === '发现'} onPress={() => {
this.setState({
selectedTab: '发现',
notifCount: this.state.notifCount + 1,
});
}}
>
{this._renderContent('#cccccc', '发现', this.state.notifCount)}
</TabBarIOS.Item>
<TabBarIOS.Item
title="我的"
icon={require('./img/3.png')}
selected={this.state.selectedTab === '我的'}
badge={this.state.notifCount > 0 ? this.state.notifCount : undefined}
onPress={() => {
this.setState({
selectedTab: '我的',
notifCount: this.state.notifCount + 1,
});
}}
>
{this._renderContent('#783E33', '历史记录', this.state.notifCount)}
</TabBarIOS.Item>
<TabBarIOS.Item
title="信息"
icon={require('./img/4.png')}
selected={this.state.selectedTab === '下载'}
onPress={() => {
this.setState({
selectedTab: '下载',
presses: this.state.presses + 1
});
}}>
{this._renderContent('#21551C', '下载页面', this.state.presses)}
</TabBarIOS.Item> </TabBarIOS>
</View>
);
}
}
const styles = StyleSheet.create({
tabContent: {
flex: 1,
alignItems: 'center',
},
welcome: {
fontSize: 20,
textAlign: 'center',
marginTop: 20,
},
tabText: {
color: 'white',
margin: 50,
},
}); AppRegistry.registerComponent('Allen', () => TabBarIOSDemo )
最新文章
- iOS NSURLConnection POST异步请求封装,支持转码GBK,HTTPS等
- 使linux服务器默认使用中文字符集zh_CN.UTF-8
- Android开发-修改AVD路径
- iOS--iOS7摄像头识别二维码功能
- poj 1275 Cashier Employment
- Asp.Net--主题/皮肤文件
- python学习第一天内容整理
- ActionMode 就记这么一点,不能更多了
- co源码解析
- macaca 测试web(2)
- ZOJ-2091-Mean of Subsequence (反证法的运用!!)
- C# 执行oracle sql 语句出现中文不兼容的问题
- Webdings字体和Wingdings字体对照表
- vue实现带规格商品的表格编辑
- 【Leetcode】404. Sum of Left Leaves
- 关于c语言中的program_invocation_short_name
- 2018-2019-1 20189206 《Linux内核原理与分析》第七周作业
- VM 虚拟机网络配置
- 大家所说的full-stack框架到底是指什么?
- Roslyn编译器-C#动态脚本实现方案
热门文章
- Gcc ------ gcc的使用简介与命令行参数说明
- ios一些问题
- CUDA从入门到精通 - Augusdi的专栏 - 博客频道 - CSDN.NET
- MYSQL主从不同步延迟原理分析及解决方案(摘自http://www.jb51.net/article/41545.htm)
- LinkedList详解
- python+Django框架运用(一)
- MyBatis学习笔记(三)——优化MyBatis配置文件中的配置
- Linux基础命令---dump
- QTQuick控件基础(3)视图
- Cortex-M3基础