美文网首页
Swift 日历控件

Swift 日历控件

作者: 花漾爱意 | 来源:发表于2020-12-15 09:12 被阅读0次

    日历控件,使用Swift语言编写


    页面布局
    1. 根据月份,获取每月1号的起始位置

      static public func getDateWeekday(date:Date) ->Int{    
        let timeInterval:TimeInterval = date.timeIntervalSince1970
        let days = Int(timeInterval/86400)
        let weekday = ((days+4)%7+7)%7
        return weekday
      }
      
    2. 根据日期,将阳历转换成对应的农历时间

      static public func solarToLuar(solarDate:Date) ->String{
        let calendar = Calendar.init(identifier: .chinese)
        let formatter = DateFormatter()
        formatter.locale = Locale(identifier:"zh_CN")
        formatter.dateStyle = .medium
        formatter.calendar = calendar
        return formatter.string(from: solarDate)
        }
      

    效果图

    6611406-fce9f9f95390a18d.jpg

    Demo下载地址:https://github.com/LiEwan/JHDatePicker.git

    相关文章

      网友评论

          本文标题:Swift 日历控件

          本文链接:https://www.haomeiwen.com/subject/rlcvgktx.html