[英]How can I change the height of UITextField in UIAlertController in Swift?
I have added a UITextField
in a UIAlertController
. 我在UIAlertController
添加了一个UITextField
。 I want to change the height of the text field. 我想更改文本字段的高度。 I have tried this way: 我试过这种方式:
let alertController = UIAlertController(title: "Comments", message: "Write your comments here", preferredStyle: UIAlertControllerStyle.alert)
alertController.addTextField { (textField : UITextField) -> Void in
var frame: CGRect = textField.frame
frame.size.height = 100
textField.frame = frame
textField.placeholder = "comment"
print(textField.frame.size.height)
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (result : UIAlertAction) -> Void in
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
}
alertController.addAction(cancelAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
It's not working. 它不起作用。
@ the4kman给出了正确的答案,但是你可以通过使用高度锚来更容易地添加约束:
textField.addConstraint(textField.heightAnchor.constraint(equalToConstant: 100))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.