Swift   发布时间:2022-04-29  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用Swift在UIActionsheet中添加datepicker大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法从UIAlertControllerStyle.ActionSheet呈现日期选择器?有办法在ActionSheet中添加按钮并向这些按钮添加操作,但我找不到在ActionSheet中添加datepicker或任何自定义视图的解决方案.

解决方法

是不可能的,但是当用户单击文本字段时,您可以使用UItextfield输入视图和附件视图来显示关闭日期选择器

class KPDAtePickerViewController: UIViewController {
    var datePicker:UIDatePicker!
    @IBOutlet var dateTextField:UITextField!

    override func viewDidLoad() {
        var customView:UIView = UIView (frame: CGRectMake(0,100,320,160))
        customView.BACkgroundColor = UIColor.brownColor()
        datePicker = UIDatePicker(frame: CGRectMake(0,160))
        customView .addSubview(datePicker)
        dateTextField.inputView = customView
        var doneButton:UIButton = UIButton (frame: CGRectMake(100,44))
        doneButton.settitle("Done",forState: UIControlState.Normal)
        doneButton.addTarget(self,action: "datePickerSELEcted",forControlEvents: UIControlEvents.TouchUpInsidE)
        doneButton.BACkgroundColor = UIColor .blueColor()
        dateTextField.inputAccessoryView = doneButton
    }

    func datePickerSELEcted() {
        dateTextField.text =  datePicker.date.description
    }
}

大佬总结

以上是大佬教程为你收集整理的使用Swift在UIActionsheet中添加datepicker全部内容,希望文章能够帮你解决使用Swift在UIActionsheet中添加datepicker所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。