【发布时间】:2015-09-03 23:27:29
【问题描述】:
我正在使用 NSDate,我得到了要显示的日期,它使用 iphone 时间更改它。我现在在按下按钮时无法更改日期,无论是更早还是第二天。我需要它像在健身应用程序中一样,它们有两个箭头,你可以按左边的箭头去上一个日期,按右边的箭头去第二天。我该怎么做?这是我现在拥有的代码:
override func didMoveToView(view: SKView) {
dateLabel.zPosition = 22
dateLabel.fontName = "Krungthep"
dateLabel.fontColor = UIColor.whiteColor()
dateLabel.fontSize = 17
dateLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: NSDateFormatterStyle.FullStyle, timeStyle: NSDateFormatterStyle.NoStyle)
dateLabel.position = CGPointMake(self.size.width / 2.0, self.size.height / 1.1)
self.addChild(dateLabel)
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch: UITouch = touches.first as! UITouch
var location = touch.locationInNode(self)
var node = self.nodeAtPoint(location)
if node.name == "next" {
//next day
}
if node.name == "before" {
//previous day
let earlyDate = NSCalendar.currentCalendar().dateByAddingUnit(NSCalendarUnit.CalendarUnitDay,value: -1,toDate:
NSDate(),options: NSCalendarOptions.WrapComponents)
date.earlierDate(earlyDate!)
}
【问题讨论】: