迅速:
我有一个UILabel,它在Camera Preview上显示TimeStamp .
var timeStampTimer : NSTimer?
var dateEnabled: Bool?
var timeEnabled: Bool?
@IBOutlet weak var timeStampLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
//Setting Initial Values to be false.
dateEnabled = false
timeEnabled = false
}
override func viewWillAppear(animated: Bool) {
//Current Date and Time on Preview View
timeStampLabel.text = timeStamp
self.timeStampTimer = NSTimer.scheduledTimerWithTimeInterval(1.0,target: self, selector: Selector("updateCurrentDateAndTimeOnTimeStamperLabel"),userInfo: nil,repeats: true)
}
func updateCurrentDateAndTimeOnTimeStamperLabel()
{
//Every Second, it updates time.
switch (dateEnabled, timeEnabled) {
case (true?, true?):
timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .LongStyle, timeStyle: .MediumStyle)
break;
case (true?, false?):
timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .LongStyle, timeStyle: .NoStyle)
break;
case (false?, true?):
timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .NoStyle, timeStyle: .MediumStyle)
break;
case (false?, false?):
timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .NoStyle, timeStyle: .NoStyle)
break;
default:
break;
}
}
我正在设置一个设置按钮来触发alertView .
@IBAction func settingsButton(sender : AnyObject) {
let cameraSettingsAlert = UIAlertController(title: NSLocalizedString("Please choose a course", comment: ""), message: NSLocalizedString("", comment: ""), preferredStyle: .ActionSheet)
let timeStampOnAction = UIAlertAction(title: NSLocalizedString("Time Stamp on Photo", comment: ""), style: .Default) { action in
self.dateEnabled = true
self.timeEnabled = true
}
let timeStampOffAction = UIAlertAction(title: NSLocalizedString("TimeStamp Off", comment: ""), style: .Default) { action in
self.dateEnabled = false
self.timeEnabled = false
}
let dateOnlyAction = UIAlertAction(title: NSLocalizedString("Date Only", comment: ""), style: .Default) { action in
self.dateEnabled = true
self.timeEnabled = false
}
let timeOnlyAction = UIAlertAction(title: NSLocalizedString("Time Only", comment: ""), style: .Default) { action in
self.dateEnabled = false
self.timeEnabled = true
}
let cancel = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel) { action in
}
cameraSettingsAlert.addAction(cancel)
cameraSettingsAlert.addAction(timeStampOnAction)
cameraSettingsAlert.addAction(timeStampOffAction)
cameraSettingsAlert.addAction(dateOnlyAction)
cameraSettingsAlert.addAction(timeOnlyAction)
self.presentViewController(cameraSettingsAlert, animated: true, completion: nil)
}