import SwiftUI
import DateGrid
struct ContentView: View {
@State var selectedMonthDate = Date()
@State var mode = CalenderMode.month(estimateHeight: 500)
let dateInterval = DateInterval.init(start: Date.getDate(from: "2021 01 01")!, end: Date.getDate(from: "2021 12 11")!)
let screen = UIScreen.main.bounds
init(){
var dateComponents = DateComponents()
dateComponents.year = 2021
dateComponents.month = 12
dateComponents.day = 11
let userCalendar = Calendar(identifier: .gregorian) // since the components above (like year 1980) are for Gregorian
let someDateTime = userCalendar.date(from: dateComponents)
//doen't work...
selectedMonthDate = someDateTime!
}
var body: some View {
ZStack{
VStack{
Text("xxxx年 xx月")
let week = ["日","月","火","水","木","金", "土"]
HStack{
ForEach(week, id: \.self){ weekOfDay in
if weekOfDay == week[0] {
ZStack{
Text("\(weekOfDay)")
.frame(maxWidth: (screen.width/7) )
.padding(10.0)
.overlay(Circle().fill().foregroundColor(.red))
Text("\(weekOfDay)").bold()
.frame(maxWidth: (screen.width/7) )
.foregroundColor(.white)
.padding(10.0)
}
}else if weekOfDay == week[6] {
Text("\(weekOfDay)")
.frame(maxWidth: (screen.width/7) )
.padding(10.0)
.overlay(Circle().stroke(lineWidth: 2.0))
.foregroundColor(.blue)
}else{
Text("\(weekOfDay)")
.frame(maxWidth: (screen.width/7) )
.padding(10.0)
.overlay(Circle().stroke(lineWidth: 2.0))
.foregroundColor(.black)
}
}
}.frame(maxWidth:.infinity)
ScrollView{
DateGrid(interval: dateInterval , selectedMonth: $selectedMonthDate, mode: .month(estimateHeight: 600)) { dateGridDate in
VStack{
if Int(Calendar.current.component(.weekday, from: dateGridDate.date)) == 7 {
Text("\(dateGridDate.date.day)")
.padding(10.0)
.overlay(
Circle()
.stroke(lineWidth: 2.0)
)
.foregroundColor(.blue)
}else if Int(Calendar.current.component(.weekday, from: dateGridDate.date)) == 1 {
Text("\(dateGridDate.date.day)")
.padding(10.0)
.overlay(
Circle()
.stroke(lineWidth: 2.0)
)
.foregroundColor(.red)
}else{
Text("\(dateGridDate.date.day)")
.padding(10.0)
.overlay(
Circle()
.stroke(lineWidth: 2.0)
)
.foregroundColor(.black)
}
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
댓글
댓글 쓰기