2016-05-26 2 views
0

Я хочу увеличить начальную высоту UITextField на UIAlertController. Вот мой код:Swift - размер текстового поля на UIAlertcontrller

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) 

Дело в том, что даже я переназначить размер кадра, это не отражается в боевой готовности. Любая помощь будет оценена.

Отредактировано: Или я хочу узнать, как увеличить высоту, когда она достигает конца ширины.

ответ

0

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

Это был tf.layoutIfNeeded(). Во всяком случае, он не работает. – hikki

+0

'self.layoutIfNeeded()' будет отображать все подпункты 'UIView' текущего' UIViewController', лучше использовать 'self', потому что это также вычисляется с другими subviews. Поэтому, если в другом подвью есть изменение кадра, это будет правильно вычисляться. В любом случае, вы должны попробовать его на своем 'reportAlertController'. А также вы должны называть 'self.layoutIfNeeded()' в блоке завершения 'presentViewController' – AnthonyR

+0

Он не работает. Хм ... Есть ли другой способ? – hikki

Смежные вопросы