加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift UIAlertController与pickerView按钮操作熬夜

发布时间:2020-12-14 05:29:33 所属栏目:百科 来源:网络整理
导读:我是 swift的新手,我正在尝试用PickerView制作UIAlertContoller 但是我对Buttones有疑问, 这是一张照片 当我试图改变约束时,按钮保持不动 我在这里读了很多答案,但我没有找到任何solotuin 这是我的代码: func distance(){ let editRadiusAlert = UIAlertCon
我是 swift的新手,我正在尝试用PickerView制作UIAlertContoller
但是我对Buttones有疑问,
这是一张照片

当我试图改变约束时,按钮保持不动
我在这里读了很多答案,但我没有找到任何solotuin

这是我的代码:

func distance(){
    let editRadiusAlert = UIAlertController(title: "Choose distance",message: "",preferredStyle: UIAlertControllerStyle.alert)
    let pickeViewFrame: CGRect = CGRect(x: 0,y: 0,width: 250,height: 300)
    let pickerViewRadius: UIPickerView = UIPickerView(frame: pickeViewFrame)
    pickerViewRadius.delegate = self
    pickerViewRadius.dataSource = self
    editRadiusAlert.view.addSubview(pickerViewRadius)
    editRadiusAlert.addAction(UIAlertAction(title: "Done",style: UIAlertActionStyle.default,handler:nil))
    editRadiusAlert.addAction(UIAlertAction(title: "Cancel",style: UIAlertActionStyle.cancel,handler: nil))
    editRadiusAlert.view.addConstraint(NSLayoutConstraint(item: editRadiusAlert.view,attribute: NSLayoutAttribute.height,relatedBy: NSLayoutRelation.equal,toItem: nil,attribute: NSLayoutAttribute.notAnAttribute,multiplier: 1,constant: self.view.frame.height * 0.5))
    self.present(editRadiusAlert,animated: true,completion: nil)
}
而不是添加pickerView作为子视图尝试设置UIAlertController的contentViewController像这样.
let vc = UIViewController()
vc.preferredContentSize = CGSize(width: 250,height: 300)
let pickerView = UIPickerView(frame: CGRect(x: 0,height: 300))
pickerView.delegate = self
pickerView.dataSource = self
vc.view.addSubview(pickerView)
let editRadiusAlert = UIAlertController(title: "Choose distance",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)

它看起来像下面.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读