[英]How to Center an Icon in a Button?
I am trying to use a button for navigation, so I want the button to be a group of an icon and text that I can click to navigate to a new page.我正在尝试使用按钮进行导航,因此我希望该按钮是一组图标和文本,我可以单击它们以导航到新页面。 The functionality works by doing this:
该功能通过以下方式工作:
<FontAwesome5.Button style={styles.iconButton} name="history" size={10} color={Colors.light.tabBackground} onPress={() => navigation.navigate('TabOneScreen')}>
<Text style={styles.subText} lightColor={Colors.light.tabBackground}>History</Text>
</FontAwesome5.Button>
...
const styles = StyleSheet.create({
iconButton: {
flexDirection: "column",
justifyContent: 'center',
alignItems: 'center',
width: 100,
backgroundColor: 'red',
},
});
This button is rendered like so:此按钮呈现如下:
The vertical spacing is fine.垂直间距很好。 However, while the text is centered horizontally, the icon obviously isn't.
然而,虽然文本水平居中,但图标显然不是。 No matter what styles I have tried, I have been unable to get the icon and text to both be centered horizontally as a button.
无论我尝试过什么 styles ,我都无法将图标和文本都作为按钮水平居中。 The background would normally be removed, but I added it here for debug purposes.
背景通常会被删除,但我在这里添加它是出于调试目的。
add the style directly to the icon:直接给图标添加样式:
<FontAwesome5.Button iconStyle={{ alignSelf: 'center' }} ...ther props>
...text
</FontAwesome5.Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.