Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift UIAlertController与pickerView按钮操作熬夜大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我是 swift的新手,我正在尝试用PickerView制作UIAlertContoller 但是我对Buttones有疑问, 这是一张照片   当我试图改变约束时,按钮保持不动 我在这里读了很多答案,但我没有找到任何solotuin 这是我的代码: func distance(){ let editRadiusAlert = UIAlertController(title: "Choos
我是 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)

它看起来像下面.

大佬总结

以上是大佬教程为你收集整理的swift UIAlertController与pickerView按钮操作熬夜全部内容,希望文章能够帮你解决swift UIAlertController与pickerView按钮操作熬夜所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: