Tag: SWIFTdateselect器

如何设置dateselect器的最短date从今天起一个月

我用xcode7.3.1使用swift。 我想设置我的dateselect器的最小date必须从今天起一个月。我正在使用下面的代码。我认为它不正确的方式。请你帮我在这种情况下。 let calendar = NSCalendar.currentCalendar() let oneMonthBack = calendar.dateByAddingUnit(.Day, value: -30, toDate: NSDate(), options: []) datePicker.minimumDate = oneMonthBack

使用NSUserdefaults保存datePicker值(xcode,swift2)

我们如何通过nsuserdeafaults或者任何东西来保存datepicker的值。例如,如果一个人select下午5点,那么当他返回到应用程序时,他应该在datepicker上看到下午5点。我不知道如何将nsusersdefault包含到下面的代码 @IBAction func NotificationButtonTapped(sender: AnyObject) { cancelLocalNotificationsWithUUID("NotificationID") //dateformatter for alert var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "hh:mm a" var strDate = dateFormatter.stringFromDate(datePicker.date) var notifications:UILocalNotification = UILocalNotification() notifications.fireDate = datePicker.date notifications.timeZone = NSTimeZone.defaultTimeZone() notifications.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1 notifications.soundName = UILocalNotificationDefaultSoundName notifications.repeatInterval = NSCalendarUnit.CalendarUnitDay notifications.userInfo = ["UUID": "NotificationID"] notifications.alertBody = "Quote of the day" UIApplication.sharedApplication().scheduleLocalNotification(notifications) }