如何修改swiftui 2的datePicker样式?
How to modify datePicker style swiftui 2?
我有一个在 swiftui 2 中用 datePicker 制作的日历,我想自定义这个日历我已经看过 .datePickerStyle() 和所有这些样式,但它不符合我的期望,我正在尝试重现(下)
我当前的代码
import SwiftUI
struct ExercisePageView: View {
@State var date = Date()
var dateFormat = DateFormat()
var dateStyle = GraphicalDatePickerStyle()
var closedRange: ClosedRange<Date> {
let currentDate = Calendar.current.date(byAdding: .day, value: 0, to: Date())!
let fiveDaysLater = Calendar.current.date(byAdding: .day, value: 5, to: Date())!
return currentDate...fiveDaysLater
}
var body: some View {
HStack {
VStack{
Text("\(dateFormat.dateToString("dd / MMMM", date))")
DatePicker("date picker test", selection: $date, in: closedRange , displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())
.clipped()
.labelsHidden()
.accentColor(Color(UIColor.systemRed))
}
}
}
}
我的代码的结果
好的,谢谢阅读这篇文章的人post我们不能像 Sweeper 所说的那样修改,你必须创建自己的组件
我有一个在 swiftui 2 中用 datePicker 制作的日历,我想自定义这个日历我已经看过 .datePickerStyle() 和所有这些样式,但它不符合我的期望,我正在尝试重现(下)
我当前的代码
import SwiftUI
struct ExercisePageView: View {
@State var date = Date()
var dateFormat = DateFormat()
var dateStyle = GraphicalDatePickerStyle()
var closedRange: ClosedRange<Date> {
let currentDate = Calendar.current.date(byAdding: .day, value: 0, to: Date())!
let fiveDaysLater = Calendar.current.date(byAdding: .day, value: 5, to: Date())!
return currentDate...fiveDaysLater
}
var body: some View {
HStack {
VStack{
Text("\(dateFormat.dateToString("dd / MMMM", date))")
DatePicker("date picker test", selection: $date, in: closedRange , displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())
.clipped()
.labelsHidden()
.accentColor(Color(UIColor.systemRed))
}
}
}
}
我的代码的结果
好的,谢谢阅读这篇文章的人post我们不能像 Sweeper 所说的那样修改,你必须创建自己的组件