Swift - UIAlertcontrller上的文本字段大小

时间:2016-05-26 20:13:51

标签: ios swift uitextfield uialertcontroller

我想在UIAlertController上增加UITextField的初始高度。 这是我的代码:

let reportAlertController = UIAlertController(title: "Report", message: "If you find anything to report, please write it in the text box below and press send. To cancel report, press cancel.", preferredStyle: .Alert)
reportAlertController.addTextFieldWithConfigurationHandler({ (tf) -> Void in
  tf.frame.size.height = 1500
  tf.placeholder = "Report detail(s) here"
})


reportAlertController.addAction(UIAlertAction(title: "Send", style: UIAlertActionStyle.Default, handler: nil))
reportAlertController.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
presentViewController(reportAlertController, animated: true, completion: nil)

事情是,即使我重新分配帧大小,它也不会反映在警报中。任何帮助将不胜感激。

编辑: 或者我想知道在达到宽度末端时扩展高度的方法。

1 个答案:

答案 0 :(得分:0)

尝试:

    let reportAlertController = UIAlertController(title: "Report", message: "If you find anything to report, please write it in the text box below and press send. To cancel report, press cancel.", preferredStyle: .Alert)
reportAlertController.addTextFieldWithConfigurationHandler({ (tf) -> Void in
  tf.frame.size.height = 1500
  tf.placeholder = "Report detail(s) here"
})


reportAlertController.addAction(UIAlertAction(title: "Send", style: UIAlertActionStyle.Default, handler: nil))
reportAlertController.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
presentViewController(reportAlertController, animated: true, completion: nil)

reportAlertController.addAction(UIAlertAction(title: "Send", style: UIAlertActionStyle.Default, handler: nil))
reportAlertController.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
presentViewController(reportAlertController, animated: true, completion: { () -> Void in
           self.layoutIfNeeded() //Update frame
        })