gpt4 book ai didi

ios - 按钮拒绝在容器中水平居中

转载 作者:行者123 更新时间:2023-11-29 00:20:15 24 4
gpt4 key购买 nike

我想掌握 React Native 的窍门,但出于某种原因,我无法让按钮在 View 容器中水平居中。

export default class LoginScreen extends Component {
static navigationOptions = {
header: null,
}
render() {
return (
<View style={styles.container}>
<MKTextField
tintColor={config.colors.accent}
floatingLabelEnabled={true}
autoFocus={true}
textInputStyle={{color: config.colors.primary, height: 32}}
placeholder="Login"
style={styles.loginInput}
onTextChange={(text) => this.setState({text})} />
<MKButton
style={styles.button}
shadowRadius={2}
shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={() => {
console.log('hi, raised button!');
}}>
<Text pointerEvents="none"
style={{color: 'white', fontWeight: 'bold', alignSelf:'center'}}>
Login
</Text>
</MKButton>
</View>
);
}
}

const styles = StyleSheet.create({
loginInput: {
width: '100%'
},
logo: {
height: '25%'
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
paddingLeft: 16,
paddingRight: 16
},
button: {
backgroundColor: config.colors.primary,
borderWidth: 0,
height: 40,
justifyContent: 'center',
alignItems: 'center',
}
});

它是这样的:Screenshot

真的不知道这里出了什么问题!

最佳答案

在您的样式中,您需要将 alignItems 更改为 alignSelf

button: {
backgroundColor: config.colors.primary,
borderWidth: 0,
height: 40,
justifyContent: 'center',
alignSelf: 'center',
}

关于ios - 按钮拒绝在容器中水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44335385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com