我希望从特定日期作为参数绘制一个经典的日历日视图。这是我的代码:
import SwiftUI
struct CalendarDayView: View {
var day = Date()
var body: some View {
VStack {
// day of the week
Text(day,
format: Date.FormatStyle().weekday(.wide))
.font(.caption)
.foregroundStyle(.primary)
.background(.red)
.clipShape(.rect)
// day number in month
Text(day,
format: Date.FormatStyle().weekday(.twoDigits))
.font(.title)
.clipShape(.rect)
.foregroundStyle(.red)
.background(.primary)
// Month and Year
HStack {
// Month
Text(day,
format: Date.FormatStyle().month(.wide))
// Year
Text(day,
format: Date.FormatStyle().year(.twoDigits))
} .font(.caption)
.clipShape(.rect)
.foregroundStyle(.primary)
.background(.red)
}
.frame(width: 60, height: 60)
}
}
我离想要的结果不远了: