如何使标签水平居中。我使用textAlign:'center'。但它不起作用。我的代码是 https://rnplay.org/apps/ZN2gvA
'use strict';
import React from 'react-native';
const {
AppRegistry,
Component,
Text,
View
}=React;
const styles=React.StyleSheet.create({
container:{
paddingTop:20,
textAlign:'center',
},
label:{
color:'blue',
backgroundColor:'red'
}
})
class SampleApp extends Component{
render(){
return (<View style={styles.container}><Text style={styles.label}>hello</Text></View>)
}
}
AppRegistry.registerComponent('SampleApp', () => SampleApp);
答案 0 :(得分:2)
你应该多关注React Native给你的警告:
样式textAlign: 'center'
仅适用于Text
个组件。请查看View
和Text
的样式文档。
在您的情况下,从textAlign: 'centre'
移除container
并将其添加到label
。查看我在https://rnplay.org/apps/RQX5Fw