gpt4 book ai didi

swift - 如何更改 UIAlertController 高度?

转载 作者:IT王子 更新时间:2023-10-29 05:22:10 26 4
gpt4 key购买 nike

我创建了一个 UIAlertController

let alertC = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alertC.addTextFieldWithConfigurationHandler(addTextField)
alertC.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
alertC.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: okButton))
presentViewController(alertC, animated: true, completion: nil)

但在那之后我想改变 UIAlertController 的高度?我该怎么做?

最佳答案

我发现您可以在呈现 View Controller 之前添加约束

 let alertController = UIAlertController(title: nil, message: "hello", preferredStyle: .alert)


let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
// hide action sheet
}
alertController.addAction(cancelAction)


var height:NSLayoutConstraint = NSLayoutConstraint(
item: alertController.view, attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1, constant: self.view.frame.height * 0.80)
alertController.view.addConstraint(height);
self.present(alertController, animated: true, completion: nil)

关于swift - 如何更改 UIAlertController 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25019701/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com