SwiftUI 中的进度日历
Progress Calendar in SwiftUI
我正在我的应用程序中构建进度日历功能。我的应用程序中有一个进度条,如果用户在当天达到 100%,我想在日历中向他们显示一个复选标记,以便他们可以看到他们在哪几天完成了目标。
构建它的方法是什么?
我想我可以为每个月的每一天设置一个变量,并在用户当天达到 100% 时使其为真,但这似乎是一个非常糟糕的解决方案。
这是我的日历使用情况。
CalendarView(interval: year) { date in
if calendar.component(.day, from: date) == calendarCurrent.component(.day, from: currentDate) {
ZStack {
Text("30")
.hidden()
.padding(8)
.overlay(
RoundedRectangle(cornerRadius: 10,
style: .continuous)
.stroke(Color(red: 50/255, green: 104/255, blue: 144/255), style: StrokeStyle(lineWidth: 2)))
.padding(.vertical, 4)
.overlay(
Text(String(self.calendar.component(.day, from: date))).bold())
.foregroundColor(.white)
}
} else {
ZStack {
Text("30")
.hidden()
.padding(8)
.background(Color(red: 50/255, green: 104/255, blue: 144/255))
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(.vertical, 4)
.overlay(
Text(String(self.calendar.component(.day, from: date))).bold())
.foregroundColor(.white)
}
}
}
我可以通过将数据保存到字典中并每天更新它的值来解决这个问题。
我正在我的应用程序中构建进度日历功能。我的应用程序中有一个进度条,如果用户在当天达到 100%,我想在日历中向他们显示一个复选标记,以便他们可以看到他们在哪几天完成了目标。 构建它的方法是什么? 我想我可以为每个月的每一天设置一个变量,并在用户当天达到 100% 时使其为真,但这似乎是一个非常糟糕的解决方案。
这是我的日历使用情况。
CalendarView(interval: year) { date in
if calendar.component(.day, from: date) == calendarCurrent.component(.day, from: currentDate) {
ZStack {
Text("30")
.hidden()
.padding(8)
.overlay(
RoundedRectangle(cornerRadius: 10,
style: .continuous)
.stroke(Color(red: 50/255, green: 104/255, blue: 144/255), style: StrokeStyle(lineWidth: 2)))
.padding(.vertical, 4)
.overlay(
Text(String(self.calendar.component(.day, from: date))).bold())
.foregroundColor(.white)
}
} else {
ZStack {
Text("30")
.hidden()
.padding(8)
.background(Color(red: 50/255, green: 104/255, blue: 144/255))
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(.vertical, 4)
.overlay(
Text(String(self.calendar.component(.day, from: date))).bold())
.foregroundColor(.white)
}
}
}
我可以通过将数据保存到字典中并每天更新它的值来解决这个问题。