问题
I want to increase the initial height of UITextField on UIAlertController. Here is my code:
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)
The thing is that even I reassign the frame size, it is not reflected in alert. Any help will be appreciated.
Edited: Or I want to know the way to expand the height as it reaches the end of width.
回答1:
Try :
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
})
来源:https://stackoverflow.com/questions/37470143/swift-size-of-textfield-on-uialertcontrller