------------------------------------------------------------------------------------------
// // ViewController.swift // UIDatePickerSample // // Created by jinnchang on 15/4/2. // Copyright (c) 2015年 Jinn Chang. All rights reserved. // import UIKit class ViewController: UIViewController { var datePicker: UIDatePicker! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. datePicker = UIDatePicker(frame: CGRectMake(0,self.view.frame.size.height - 400,self.view.frame.size.width,400)) datePicker.datePickerMode = .DateAndTime datePicker.date = NSDate() datePicker.addTarget(self,action: "datePickerValueChange:",forControlEvents: .ValueChanged) self.view.addSubview(datePicker) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /// 响应 datePicker 事件 func datePickerValueChange(sender: UIDatePicker) { println("value change: \(sender.date)") } }------------------------------------------------------------------------------------------
GitHub 上项目地址:UIDatePickerSample
控件更多相关属性及方法参考:UIDatePicker Class Reference 文章最后更新时间:2015年4月3日11:18:10