빠른:
카메라 미리보기를 통해 타임 스탬프를 표시하는 UILabel이 있습니다.
var timeStampTimer : NSTimer?
var dateEnabled: Bool?
var timeEnabled: Bool?
@IBOutlet weak var timeStampLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
dateEnabled = false
timeEnabled = false
}
override func viewWillAppear(animated: Bool) {
timeStampLabel.text = timeStamp
self.timeStampTimer = NSTimer.scheduledTimerWithTimeInterval(1.0,target: self, selector: Selector("updateCurrentDateAndTimeOnTimeStamperLabel"),userInfo: nil,repeats: true)
}
func updateCurrentDateAndTimeOnTimeStamperLabel()
{
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)
}