Swift - size of textfield on UIAlertcontrller

孤人 提交于 2019-12-12 00:05:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!