如何在Swift中的UIAlertController中更改UITextField的高度? [英] How can I change the height of UITextField in UIAlertController in Swift?
本文介绍了如何在Swift中的UIAlertController中更改UITextField的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在UIAlertController
中添加了UITextField
.我想更改文本字段的高度.我已经尝试过这种方式:
I have added a UITextField
in a UIAlertController
. 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)
它不起作用.
推荐答案
这适用于约束.
alertController.addTextField { textField in
let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 100)
textField.addConstraint(heightConstraint)
}
这篇关于如何在Swift中的UIAlertController中更改UITextField的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文