如何将UIPickerView置于UIAlertController的中心?
现在我有这个代码:
let alertController = UIAlertController(title: "Представьтесь пожалуйста", message: "Кто вы?", preferredStyle: .alert)
alertController.isModalInPopover = true
userTypePickerView = UIPickerView(frame: CGRect(x: 0,
y: 0,
width: alertController.view.bounds.size.width,
height: 140))
userTypePickerView.delegate = self
userTypePickerView.dataSource = self
let height: NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 240)
alertController.view.addConstraint(height)
alertController.view.addSubview(userTypePickerView)
而我看到这张照片...
尽管我投票支持创建自定义警报,但您可以这样做
let alertController = UIAlertController(title: "Представьтесь пожалуйста", message: "Кто вы?", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "ok", style: .default, handler: nil))
alertController.isModalInPopover = true
let userTypePickerView = UIPickerView(frame:.zero)
alertController.view.addSubview(userTypePickerView)
userTypePickerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
userTypePickerView.widthAnchor.constraint(equalToConstant: 200),
userTypePickerView.heightAnchor.constraint(equalToConstant: 200),
userTypePickerView.topAnchor.constraint(equalTo: alertController.view.topAnchor,constant:70),
userTypePickerView.bottomAnchor.constraint(equalTo: alertController.view.bottomAnchor,constant:-40),
userTypePickerView.centerXAnchor.constraint(equalTo: alertController.view.centerXAnchor)
])
userTypePickerView.backgroundColor = .red
self.present(alertController, animated: true, completion: nil)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句