欢迎光临散文网 会员登陆 & 注册

swiftUI零基础学习 制作ios日历基础知识

2023-02-15 13:30 作者:再不学就没学上了  | 我要投稿

代码

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()

  }

}

效果


swiftUI零基础学习 制作ios日历基础知识的评论 (共 条)

分享到微博请遵守国家法律