小编Mat*_*tti的帖子

DatePicker配置swift

对不起我的英语和问题!

我正在使用带有swift的xCode 6

我正在尝试开发自己的应用程序,我不知道如何要求用户设置日期,所以我可以在另一方使用该值:我不在乎它是否使用带滚动的DatePicker或另外,只需要用户可以设置任何日期.我无法猜测datePicker是如何工作的:S

我在开发"Tinder"的课程中找到了这个代码,当它在登录时询问你的出生日期时,我将它调整到我的应用程序,但它不起作用,我不知道为什么:S

import UIKit

class SignUpController: UIViewController, UITextFieldDelegate {

var pickerContainer = UIView()
var picker = UIDatePicker()

@IBOutlet weak var selectedDate: UIButton!


override func viewDidLoad() {
    super.viewDidLoad()


    self.selectedDate.setTitle("", forState: UIControlState.Normal)

    configurePicker()
}

func configurePicker()
{
    pickerContainer.frame = CGRectMake(0.0, 600.0, 320.0, 300.0)
    pickerContainer.backgroundColor = UIColor.whiteColor()

    picker.frame    = CGRectMake(0.0, 20.0, 320.0, 300.0)
    picker.setDate(NSDate(), animated: true)
    picker.maximumDate = NSDate()
    picker.datePickerMode = UIDatePickerMode.Date
    pickerContainer.addSubview(picker)

    var doneButton = UIButton()
    doneButton.setTitle("Done", forState: UIControlState.Normal)
    doneButton.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
    doneButton.addTarget(self, action: Selector("dismissPicker"), forControlEvents: UIControlEvents.TouchUpInside)
    doneButton.frame    = …
Run Code Online (Sandbox Code Playgroud)

date datepicker swift xcode6

3
推荐指数
1
解决办法
7392
查看次数

标签 统计

date ×1

datepicker ×1

swift ×1

xcode6 ×1