ios - 使用 Swift 3.0 在 iOS 中禁用以前的日期、月份、年份 JTAppleCalendar
<p><p>我正在使用这个库:<br/>
<a href="https://github.com/orazz/CalendarPopUp" rel="noreferrer noopener nofollow">https://github.com/orazz/CalendarPopUp</a> </p>
<p>假设我有一个用户注册日期,它是 2017 年 9 月 28 日。现在我只想启用下一个日期、月份和年份之间的日期。
应禁用以前的日期、月份和年份。</p>
<p>我该怎么做?</p>
<p>如何禁用滚动和选择上一个日期和月份?</p>
<p> <a href="/image/HjLWi.png" rel="noreferrer noopener nofollow"><img src="/image/HjLWi.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用它来设置最小和最大日期。您可以更改任何组件,例如日、月、年。 </p>
<p><strong> objective-c </strong></p>
<pre><code>NSCalendar *calendar = [ initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *currentDate = ;
NSDateComponents *comps = [ init];
;
NSDate *maxDate = ;
;
NSDate *minDate = ;
;
;
</code></pre>
<hr/>
<p><strong> swift </strong></p>
<pre><code>let gregorian: NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let currentDate: NSDate = NSDate()
let components: NSDateComponents = NSDateComponents()
components.month = -3
let minDate: NSDate = gregorian.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!
components.month = 3
let maxDate: NSDate = gregorian.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!
self.datePicker.minimumDate = minDate
self.datePicker.maximumDate = maxDate
</code></pre></p>
<p style="font-size: 20px;">关于ios - 使用 Swift 3.0 在 iOS 中禁用以前的日期、月份、年份 JTAppleCalendar,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46465319/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46465319/
</a>
</p>
页:
[1]