Swift 简单控件示例:日期选择器(UIDatePicker)

前端之家收集整理的这篇文章主要介绍了Swift 简单控件示例:日期选择器(UIDatePicker)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
转载请声明出处:http://www.jb51.cc/article/p-qwzwtpxe-ga.html
------------------------------------------------------------------------------------------

//
//  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
原文链接:https://www.f2er.com/swift/327411.html

猜你在找的Swift相关文章