Swift: Set custom Date(Day only) in DatePicker

给你一囗甜甜゛ 提交于 2019-12-25 18:12:41

问题


I search and try this for a couple hour. I have 2 date picker. Let say fromDatePicker and untilDatePicker. I set the untilDatePicker to current date (ex: 12/06/17) and i want to set the fromDatePicker into first date of the current month (ex: 01/06/17) but i dont have any idea to set the untilDatePicker. I have read this but its not help me to much. Any sugest and answer will help for me. Thanks in Advance


回答1:


This is swift3 solution and how you set first day of current month in datePicker , if you need to get first of other month just change date variable with some day from that month

    let date = NSDate()
    let calendar = NSCalendar.current
    let components = calendar.dateComponents([.year,.month], from: date as Date)
    let startOfMonth = calendar.date(from: components)
    self.datePicker.setDate(startOfMonth!, animated: true)


来源:https://stackoverflow.com/questions/44493102/swift-set-custom-dateday-only-in-datepicker

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!