在UIAlertView中设置TextField和PickerView

时间:2017-04-19 19:58:53

标签: swift3 xcode8.2

我想创建一个包含文本字段和选择器视图的警报。 我希望首先在顶部显示选择器视图,然后在选择器视图下面的文本字段。

enter image description here

这是我的代码

df <- structure(list(rownames = c("Sparse Dual Stream", "Heterogeneous Dual Stream A", 
"Heterogeneous Dual Stream B", "Dense Dual Stream", "Radical Storage", 
"Radical Sparse Comp.", "Radical Heterogeneous Comp. B", "Radical Dense Comp.", 
"Radical Heterogeneous Comp. A"), AIC.means = c(-4632.137, -4627.653, 
-4622.063, -4616.507, -4615.934, -4601.292, -4600.65, -4589.49, 
-4587.993), AIC.lci = c(-4655.353, -4650.866, -4645.194, -4639.633, 
-4639.052, -4624.428, -4623.785, -4612.632, -4611.141), AIC.uci = c(-4608.922, 
-4604.439, -4598.932, -4593.381, -4592.817, -4578.156, -4577.515, 
-4566.348, -4564.845)), .Names = c("rownames", "AIC.means", "AIC.lci", 
"AIC.uci"), row.names = c(NA, -9L), class = "data.frame")

4 个答案:

答案 0 :(得分:1)

您应该创建一个uiviewcontroller并为其提供此效果。

例如:在下一张图片中,我创建了一个视图作为模态。它是一个带有灰色视图的uiviewcontroller(在你的情况下,在灰色视图中你应该放置uitextfield和uipickerview)。然后,我将storyboard segue配置为模态存在并在uiviewcontroller中给出模态的效果:

self.view.backgroundColor = UIColor.black.withAlphaComponent(0.8)

enter image description here

enter image description here

答案 1 :(得分:0)

您无法使用<nav> <ul> <li>Test <ul class="drop-menu"> <li class="1">Test1</li> <li class="2">Test2 <ul class="drop-menu"> <li class="1">Test1</li> <li class="2">Test2</li> <li class="3">Test3</li> <li class="4">Test4</li> <li class="5">Test5</li> <li class="6">Test6</li> <li class="7">Test7</li> </ul> </li> <li class="3">Test3</li> <li class="4">Test4</li> <li class="5">Test5</li> <li class="6">Test6</li> <li class="7">Test7</li> </ul> </li> </ul> </nav>,因为它没有选项来添加除文本字段之外的其他视图。 所以,你必须编写自己的控件,它将模仿UIAlertController。 您可以编写视图控制器并以模态方式呈现它,或创建视图并将其添加到控制器视图中。 此外,尝试在github.comcocoacontrols.com上找到准备好的组件并根据需要进行修改可能是个好主意。

答案 2 :(得分:0)

尝试这些Pod希望它可以帮助你

https://github.com/nealyoung/NYAlertViewController

答案 3 :(得分:0)

您可以使用以下代码:

 let alertView = UIAlertController(
            title: "Select",
            message: "\n\n\n\n\n\n\n\n\n",
            preferredStyle: .alert)

        let pickerView = UIPickerView(frame:
            CGRect(x: 0, y: 50, width: 260, height: 162))
        pickerView.dataSource = self
        pickerView.delegate = self
        pickerView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.5)

        alertView.view.addSubview(pickerView)
        alertView.addTextField(configurationHandler: configurationTextField)
        alertView.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler:nil))
        alertView.addAction(UIAlertAction(title: "Ok", style: .default, handler:{ (UIAlertAction) in
            guard let text = self.textField?.text else {return}
            print(text)
        }))
        present(alertView, animated: true, completion: {
            pickerView.frame.size.width = alertView.view.frame.size.width
        })