swift UIAlertController with pickerView button action stay up

前端 未结 1 738
有刺的猬
有刺的猬 2020-12-14 18:55

I am new in swift and I am trying to make UIAlertContoller with PickerView but I have problems with the Buttones, Here a photo

相关标签:
1条回答
  • 2020-12-14 19:39

    Instead of adding pickerView as subview try to set contentViewController of UIAlertController like this.

    let vc = UIViewController()
    vc.preferredContentSize = CGSize(width: 250,height: 300)
    let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: 250, height: 300))
    pickerView.delegate = self
    pickerView.dataSource = self
    vc.view.addSubview(pickerView)
    let editRadiusAlert = UIAlertController(title: "Choose distance", message: "", preferredStyle: UIAlertControllerStyle.alert)
    editRadiusAlert.setValue(vc, forKey: "contentViewController")
    editRadiusAlert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
    editRadiusAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
    self.present(editRadiusAlert, animated: true)
    

    It's looks like below.

    0 讨论(0)
提交回复
热议问题