SWIFTクリア-(3)
7836 ワード
デート
コード#コード#
import UIKit
class ViewController: UIViewController {
let timeSelector : Selector = #selector(ViewController.updateTime)
let interval = 1.0
var count = 0
@IBOutlet var lblCurrentTime: UILabel!
@IBOutlet var lblPickerTime: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
Timer.scheduledTimer(timeInterval: interval, target: self, selector:timeSelector, userInfo: nil, repeats: true)
}
//데이터 피커를 선택할 때 발생하는 액션함수인 changeDatePicker함수가 호출되면서
//sender 라는 UIDatePicker 자료형의 인수가 전달됩니다.
@IBAction func changeDatePicker(_ sender: UIDatePicker) {
let datePickerView = sender
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm EEE"
lblPickerTime.text = "선택시간: " + formatter.string(from: datePickerView.date)
}
@objc func updateTime() {
// lblCurrentTime.text = String(count)
// count = count + 1
//현재 시간을 가져오기 위해 NSDate함수를 가져옴
let date = NSDate()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
lblCurrentTime.text = "현재시간: " + formatter.string(from: date as Date)
}
}
構文
コード#コード#
import UIKit
class ViewController: UIViewController {
let timeSelector : Selector = #selector(ViewController.updateTime)
let interval = 1.0
var count = 0
@IBOutlet var lblCurrentTime: UILabel!
@IBOutlet var lblPickerTime: UILabel!
Selectorとは?
関数をパラメータとして使用するキーワード.
import UIKit
class ViewController: UIViewController {
let timeSelector : Selector = #selector(ViewController.updateTime)
let interval = 1.0
var count = 0
@IBOutlet var lblCurrentTime: UILabel!
@IBOutlet var lblPickerTime: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
Timer.scheduledTimer(timeInterval: interval, target: self, selector:timeSelector, userInfo: nil, repeats: true)
}
//데이터 피커를 선택할 때 발생하는 액션함수인 changeDatePicker함수가 호출되면서
//sender 라는 UIDatePicker 자료형의 인수가 전달됩니다.
@IBAction func changeDatePicker(_ sender: UIDatePicker) {
let datePickerView = sender
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm EEE"
lblPickerTime.text = "선택시간: " + formatter.string(from: datePickerView.date)
}
@objc func updateTime() {
// lblCurrentTime.text = String(count)
// count = count + 1
//현재 시간을 가져오기 위해 NSDate함수를 가져옴
let date = NSDate()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
lblCurrentTime.text = "현재시간: " + formatter.string(from: date as Date)
}
}
import UIKit
class ViewController: UIViewController {
let timeSelector : Selector = #selector(ViewController.updateTime)
let interval = 1.0
var count = 0
@IBOutlet var lblCurrentTime: UILabel!
@IBOutlet var lblPickerTime: UILabel!
Reference
この問題について(SWIFTクリア-(3)), 我々は、より多くの情報をここで見つけました https://velog.io/@h0h0h000/Swift-정리-3テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol