Swift - UIAlertcontrller 上文本字段的大小 [英] Swift - size of textfield on UIAlertcontrller

查看:22
本文介绍了Swift - UIAlertcontrller 上文本字段的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

尝试:

    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
        })

这篇关于Swift - UIAlertcontrller 上文本字段的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆