时间框显示在其他部位
let theRunLoop = NSRunLoop.currentRunLoop() as NSRunLoop
let fireDate = NSDate(timeIntervalSinceNow: 0)
let thetimer = NSTimer.init(fireDate: fireDate, interval: 1, target: self, selector: "timeMethod", userInfo: nil, repeats: true)
theRunLoop.addTimer(thetimer, forMode: NSDefaultRunLoopMode)
func timeMethod(){
let date = NSDate()
let timeFomatter = NSDateFormatter()
timeFomatter.dateFormat = "HH:mm"
let strNowTime = timeFomatter.stringFromDate(date) as String
self.timeLabel.text = strNowTime
}
self.timeLabel 是显示时间的label
时间: 2024-10-25 00:37:52