swift – 如何更改UIAlertController高度?

前端之家收集整理的这篇文章主要介绍了swift – 如何更改UIAlertController高度?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个UIAlertController
  1. let alertC = UIAlertController(title: "Title",message: "Message",preferredStyle: UIAlertControllerStyle.Alert)
  2. alertC.addTextFieldWithConfigurationHandler(addTextField)
  3. alertC.addAction(UIAlertAction(title: "Cancel",style: UIAlertActionStyle.Default,handler: nil))
  4. alertC.addAction(UIAlertAction(title: "OK",handler: okButton))
  5. presentViewController(alertC,animated: true,completion: nil)

但之后我想改变UIAlertController的高度?我怎样才能做到这一点?

我发现在呈现视图控制器之前可以添加约束
  1. let alertController = UIAlertController(title: nil,message: "hello",preferredStyle: .Alert)
  2.  
  3.  
  4. let cancelAction = UIAlertAction(title: "Cancel",style: .Cancel) { (action) in
  5. // hide action sheet
  6. }
  7. alertController.addAction(cancelAction)
  8.  
  9.  
  10. var height:NSLayoutConstraint = NSLayoutConstraint(item: alertController.view,attribute: NSLayoutAttribute.Height,relatedBy: NSLayoutRelation.Equal,toItem: nil,attribute: NSLayoutAttribute.NotAnAttribute,multiplier: 1,constant: self.view.frame.height * 0.80)
  11. alertController.view.addConstraint(height);
  12. self.presentViewController(alertController,completion: nil)

猜你在找的Swift相关文章