日期选择器,用户无法回到以前的日期Swift

时间:2016-06-29 07:44:36

标签: swift uidatepicker

我有日期选择器

我已经设置了当前日期,我想让用户无法滚动回上一个日期?是允许的吗?

3 个答案:

答案 0 :(得分:1)

正如文件所说here 你只需要设置你的UIDatePicker的选项 minimumDate

这是一个例子

<div class="panel panel-default panel-height" ng-repeat="candidateInfo in aCandidateDetails">
<div class="panel-heading" ng-class="{'firstChild':$first}"> <!-- Try this line -->
    <div class="row">
        <div class="col-xs-1">
            <a style="cursor:pointer">
                {{candidateInfo.name}}
            </a>
        </div>
    </div>
    <div stop-watch time="xyz" name="candidateInfo.name" time-of-interview="candidateInfo.doi" ></div>
</div>

另一个案例是以下

var datePicker = UIDatePicker() //your UIDatePicker
datePicker.minimumDate = Date() //the minimum date is now. Only future date is allowed

答案 1 :(得分:0)

在Swift 3:

var datePicker = UIDatePicker()
datePicker.minimumDate = Date()

答案 2 :(得分:0)

这是如何在 Swift 2.2

中执行此操作的示例
// a global var
var datePicker = UIDatePicker()

 // UIDatePicker settings:
 let currentDate: NSDate = NSDate()
 let calendar: NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
 calendar.timeZone = NSTimeZone(name: "UTC")!
 let components: NSDateComponents = NSDateComponents()
 components.calendar = calendar
 components.year = -18
 let minDate: NSDate = calendar.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!
 components.year = -150
 let maxDate: NSDate = calendar.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!
 datePicker.dateOfBirthUIDatePicker.minimumDate = minDate
 datePicker.dateOfBirthUIDatePicker.maximumDate = maxDate