swiftUI零基础学习 制作ios日历基础知识
代码
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("\(Date())").padding()
Text(Date().formatted(Date.FormatStyle().year().day().month()))
Text(Date().formatted(date: .abbreviated, time: .complete))
Button{
var current=Calendar.current
let toDaystart=current.startOfDay(for: Date())
print("todaystart",toDaystart)
let tommorrowStart=current.date(byAdding: .day, value: 1, to: toDaystart) ?? Date()
print("tommorrowStart",tommorrowStart)
}label:{
Text("初始时间")
}
Button{
let now=Date()
var matchingComponents=DateComponents()
matchingComponents.weekday=2
let comingDay=Calendar.current.nextDate(after: now, matching: matchingComponents, matchingPolicy: .nextTime) ?? Date()
print("comingDay",comingDay)
}label: {
Text("日期匹配")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
效果

