Untitled
unknown
plain_text
3 years ago
1.8 kB
8
Indexable
let dateInWeek = Date()
let calendar = Calendar.current
let dayOfWeek = calendar.component(.weekday, from: dateInWeek)
let weekdays = calendar.range(of: .weekday, in: .weekOfYear, for: dateInWeek)!
let days = (weekdays.lowerBound ..< weekdays.upperBound)
.compactMap { calendar.date(byAdding: .day, value: $0 - dayOfWeek, to: dateInWeek) }
let toDay: String = dateInWeek.format(format: "dd")
let weekNames = ["S", "M", "T", "W", "T", "F", "S"]
ForEach(0..<7) { i in
let thisDay: String = days[i].format(format: "dd")
VStack(alignment: .center, spacing: 15 * HR){
Text("\(weekNames[i])")
.font(.custom(FontArray[widgetData.layer2FontIndex], size: widgetData.layer2FontSize))
.foregroundColor(Color(UIColor(hexString: widgetData.layer3ColorCode).withAlphaComponent(0.5)))
.padding(EdgeInsets(top: thisDay == toDay ? 1 * HR : 0, leading: 0, bottom: 0, trailing: 0))
if thisDay == toDay {
ZStack {
Rectangle()
.frame(width: 20 * HR,height: 15 * HR)
.foregroundColor(Color(UIColor(hexString: widgetData.layer1ColorCode)))
.cornerRadius(5 * HR)
Text("\(thisDay)")
.font(.custom(FontArray[widgetData.layer3FontIndex], size: widgetData.layer3FontSize))
.foregroundColor(Color(UIColor(hexString: widgetData.layer2ColorCode)))
}.padding(EdgeInsets(top: -3 * HR, leading: 0, bottom: 0, trailing: 0))
}else {
Text("\(thisDay)")
.font(.custom(FontArray[widgetData.layer3FontIndex], size: widgetData.layer3FontSize))
.foregroundColor(Color(UIColor(hexString: widgetData.layer1ColorCode)))
}
}
}Editor is loading...