当我点击标签时,底部的快速打开日期选择器与完成和取消按钮

时间:2016-10-04 07:05:38

标签: swift uilabel

我正在使用swift和以下代码在iphone中进行应用程序

override func viewDidLoad() {
    //<#code#>
    dateSet.userInteractionEnabled = true
    let aSelector : Selector = "lblTapped"
    let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
    tapGesture.numberOfTapsRequired = 1

    dateSet.addGestureRecognizer(tapGesture)
}



func lblTapped(){
 // need to add datapicker UIView
}

1 个答案:

答案 0 :(得分:0)

使用textfield inputView将datepicker显示在底部。下面的示例代码

private func dateTextFieldSetup()

    {
        let datePickerView  : UIDatePicker = UIDatePicker()
    datePickerView.datePickerMode = UIDatePickerMode.Date
    sampleTextfield.inputView = datePickerView
    datePickerView.addTarget(self, action:#selector(CFTextField.handleDatePickerForSlectedText(_:)), forControlEvents: UIControlEvents.ValueChanged)

}

对于UILabel,inputView属性不可用。