Open UIDatePicker programmatically in iOS 14

后端 未结 9 1559
南笙
南笙 2020-12-23 16:46

I have this normal UIDatePicker (sorry that it\'s not in English, please ignore that):

\"my

9条回答
  •  孤城傲影
    2020-12-23 17:45

    I don't know if this is still valid, but you can make use of the .inline style of new UIDatePicker. Then use your own view and animations to mimic the appearance of the DatePicker from .compact style.

            let secondDatePicker = UIDatePicker()
            secondDatePicker.preferredDatePickerStyle = .inline
            self.view.addSubview(secondDatePicker)
            
            secondDatePicker.translatesAutoresizingMaskIntoConstraints = false
            secondDatePicker.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
            secondDatePicker.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    

提交回复
热议问题