如何更改UIAlertController的高度?
我创建了一个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的高度吗?我怎样才能做到这一点?
回答:
我发现您可以在显示视图控制器之前添加约束
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)
以上是 如何更改UIAlertController的高度? 的全部内容, 来源链接: utcz.com/qa/424275.html