我正在尝试使用 flexbox 将我的图标与按钮视图的左侧对齐,并将文本与中心对齐。目前它们都与中心对齐,但我不确定如何将我的图标放在按钮的最左边缘,同时保持文本在视图中居中
现在我的按钮看起来像这样:
我使用 https://github.com/APSL/react-native-button 作为按钮,使用 https://github.com/oblador/react-native-vector-icons 作为图标
下面是我的一些代码:
<Button style={signupStyles.facebookButton}>
<View style={signupStyles.nestedButtonView}>
<Icon
name="facebook"
size={30}
color={'white'}
/>
<Text style={signupStyles.buttonText}>Continue with Facebook</Text>
</View>
</Button>
var signupStyles = StyleSheet.create({
buttonText: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
facebookButton: {
backgroundColor: styleConstants.facebookColor,
borderColor: styleConstants.facebookColor,
borderWidth: 2,
borderRadius: 22,
},
nestedButtonView: {
flexDirection: 'row',
alignItems: 'center',
},
});
原文由 Stone Preston 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以通过将图标设置为
width
并给出文本padding-right
,text-align
和flex:1