【问题标题】:Swift - UIToolbar with Done button for UIPickerView disappear on landscapeSwift - UIPickerView 的带有完成按钮的 UIToolbar 在横向上消失
【发布时间】:2018-06-07 16:30:43
【问题描述】:

我将UIPickerView 作为UITextField 的输入,并使用“完成”按钮实现UIToolbar。它工作得很好,但是当我在 iPhone 上切换到横向模式时,UIToolbar 消失了。这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    thePicker.delegate = self

    let toolBar = UIToolbar()
    toolBar.barStyle = UIBarStyle.default

    toolBar.isTranslucent = true
    toolBar.tintColor = UIColor(red: 76/255, green: 100/255, blue: 217/255, alpha: 1)
    toolBar.sizeToFit()

    let doneButton = UIBarButtonItem(title: "Aceptar", style: UIBarButtonItemStyle.plain, target: self, action: #selector(doneClick))


    toolBar.setItems([doneButton], animated: false)
    toolBar.isUserInteractionEnabled = true

    testTextField.inputView = thePicker
    testTextField.inputAccessoryView = toolBar

}

【问题讨论】:

    标签: ios swift uipickerview uitoolbar


    【解决方案1】:

    当我以编程方式添加 UIPickerView 并为 PickerView 添加 UIToolBar 时遇到了同样的问题。只需要为 UIPickerView 添加 [.flexibleWidth,.flexibleHeight]

    self.thePicker.autoresizingMask = [.flexibleWidth,.flexibleHeight]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多