我有一个List显示当前月份的天数。中的每一行都List包含缩写的天,a Divider和a中的天数VStack。在VStack随后被嵌入在HStack这样我就可以有更多的文本后的今天,数量的权利。
struct DayListItem : View {
// MARK: - Properties
let date: Date
private let weekdayFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "EEE"
return formatter
}()
private let dayNumberFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "d"
return formatter
}()
var body: some View {
HStack {
VStack(alignment: .center) {
Text(weekdayFormatter.string(from: date))
.font(.caption)
.foregroundColor(.secondary)
Text(dayNumberFormatter.string(from: date))
.font(.body)
.foregroundColor(.red)
}
Divider()
}
}
} …Run Code Online (Sandbox Code Playgroud) swiftui ×1