![](/img/trans.png)
[英]Can we change the height and width of UIAlertController Buttons in swift
[英]How can I change the height of UITextField in UIAlertController in Swift?
我在UIAlertController
添加了一個UITextField
。 我想更改文本字段的高度。 我試過這種方式:
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)
它不起作用。
@ the4kman給出了正確的答案,但是你可以通過使用高度錨來更容易地添加約束:
textField.addConstraint(textField.heightAnchor.constraint(equalToConstant: 100))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.