【发布时间】:2018-04-16 03:17:28
【问题描述】:
<Tabs
initialPage={moment().date()}
tabBarUnderlineStyle={{ backgroundColor: '#5AF158' }}
renderTabBar={() => <ScrollableTab />}
>
{this.renderTabHeader()}
</Tabs>
renderTabHeader() {
return (
this.props.dateArray.map((date) =>
<Tab
heading={date.format('DD/MM') +'\n'+this.props.weekdayArray[date.day()]}
tabStyle={styles.tabStyling}
activeTabStyle={styles.activeTabStyle}
textStyle={styles.tabTextStyle}
activeTextStyle={styles.activeTabTextStyle}
>
<View style={{backgroundColor:'#EEEEEE', flex: 1}}>
<Content contentDate={date.format('DD/MM')} />
</View>
</Tab>
)
);
}
const styles = StyleSheet.create({
tabStyling: {
backgroundColor: "#37b372"
},
activeTabStyle: {
backgroundColor: "#37b372"
},
tabTextStyle: {
color: '#96DCA6'
},
activeTabTextStyle: {
fontWeight: 'bold',
color: 'white',
fontSize: 20
}
});
以上是我使用来自NativeBase 的Tab 组件的方式。在heading 部分是一个字符串,由两行组成,第一行是日期,第二行是星期几。我想知道是否有一种方法可以配置,以便这两行将具有单独的样式,而不是共享完全相同的样式,因为我正在尝试使星期几的 fontSize 更小。
更新:
实现@Pritish推荐的TabHeading块将删除所有tabStyling、activeTabStyling,如下所示:
<Tab
heading={
<TabHeading style={{ flexDirection: 'column'}}>
<Text style={{ fontSize: 20 }}>{date.format('DD/MM')}</Text>
<Text style={{ fontSize: 15 }}>{this.props.weekdayArray[date.day()]}</Text>
</TabHeading>
}
tabStyle={styles.tabStyling}
activeTabStyle={styles.activeTabStyle}
textStyle={styles.tabTextStyle}
activeTextStyle={styles.activeTabTextStyle}
>
<View style={{backgroundColor:'#EEEEEE', flex: 1}}>
<Content contentDate={date.format('DD/MM')} />
</View>
</Tab>
【问题讨论】:
标签: react-native tabs styles native-base