我想将react-native-datepicker文本向左对齐。默认情况下,它居中。我试图更改样式和自定义样式的道具,但是没有用。
如何使文本左对齐?
<DatePicker
style={styles.datePicker}
date={this.state.birthday}
mode="date"
placeholder="Birthday"
format="YYYY-MM-DD"
minDate="1950-01-01"
maxDate="2018-06-01"
confirmBtnText="Ok"
cancelBtnText="Cancel"
showIcon={false}
customStyles={{
dateInput: {
borderWidth: 0,
borderBottomWidth: 2
},
placeholderText: {
fontSize: 20,
color: "#C7C7C7"
},
dateText: {
fontSize: 20,
color: "black",
textAlign: "left"
}
}}
onDateChange={birthday => this.setState({birthday: birthday})}
/>
答案 0 :(得分:3)
只需编辑日期输入:{
alignItems:“弹性启动”
}
constructor(props) {
super(props);
this.state = {
chosenDate: new Date(),
date: '15-05-2018' ,
visible: false
};
}
<Item rounded style={[styles.inputStyle, { marginTop: 6 }]}>
<DatePicker
style={[styles.inputmain]}
placeholder= "DOB"
date={this.state.date} //initial date from state
mode="date" //The enum of date, datetime and time
placeHolderTextStyle={{ color: "#cc0000" }}
format="DD-MM-YYYY"
minDate="01-01-1900"
maxDate="01-01-2019"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
onDateChange={date => {
this.setState({ date: date });
}}
customStyles={{
dateInput: {
borderWidth: 0,
borderBottomWidth: 2,
alignItems: "flex-start"
},
placeholderText: {
fontSize: 17,
color: "white"
},
dateText: {
fontSize: 17,
color: "white",
}
}}
/>
</Item>
参考:https://github.com/xgfe/react-native-datepicker/issues/220