【发布时间】:2021-08-11 16:55:39
【问题描述】:
我正在编写的应用程序是基于事件的应用程序。在您将创建一个新事件的屏幕上,我有一个 UITextField,其中一个 UIDatePicker 设置为其输入视图,初始化为:
lazy var eventDateTxt: UITextField = {
let tf = UITextField()
tf.attributedPlaceholder = NSAttributedString(string: "Pick Your Event Date",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.zipVeryLightGray])
tf.font = .zipBody
tf.borderStyle = .roundedRect
tf.tintColor = .white
tf.backgroundColor = .zipGray
tf.textColor = .white
tf.adjustsFontSizeToFitWidth = true
tf.minimumFontSize = 10.0;
let datePicker = UIDatePicker()
datePicker.datePickerMode = .dateAndTime
datePicker.minimumDate = Date()
tf.inputView = datePicker
datePicker.addTarget(self, action: #selector(dateChanged), for: .valueChanged)
return tf
}()
dateChanged 看起来像这样
@objc func dateChanged(sender: UIDatePicker){
let dateFormat = DateFormatter()
dateFormat.dateStyle = .long
dateFormat.timeStyle = .short
eventDateTxt.text = dateFormat.string(from: sender.date)
event.startTime = sender.date
}
虽然没关系,但这是我的 UITextFieldDelegate 代码
extension NewEventViewController: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == titleText {
if textField.text == "Event Title" {
textField.text = ""
}
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
if textField == titleText {
if textField.text == "" {
textField.text = "Event Title"
}
}
}
}
现在的问题:当我单击 UITextField 打开 DatePicker 时,它会在屏幕底部弹出一个小的弹出视图,如下所示:
注意图像的最底部。
现在,如果您单击底部的日期,它会按预期打开 DatePicker,如下所示:
这样做时,控制台中会出现错误
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002d79ea0 'UIView-bottom-readableContentGuide-constraint' UILayoutGuide:0x60000379d340'UIViewLayoutMarginsGuide'.bottom == UILayoutGuide:0x60000379d260'UIViewReadableContentGuide'.bottom (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2021-08-11 12:52:37.262846-0400 zip_official[93261:10730049] [DatePicker] UIDatePicker 0x7faa2732fe80 is being laid out below its minimum width of 280. This may not look like expected, especially with larger than normal font sizes.
使用建议的断点并没有把我带到任何地方。
所以我的问题是:我怎样才能让 DatePicker 立即弹出而没有底部的小标签。
【问题讨论】:
标签: ios swift iphone uidatepicker