Ios 如何在UIAlertController中设置UIExtField的高度?
我知道通过使用此代码以编程方式设置常规文本字段的高度Ios 如何在UIAlertController中设置UIExtField的高度?,ios,swift,uitextfield,uialertcontroller,Ios,Swift,Uitextfield,Uialertcontroller,我知道通过使用此代码以编程方式设置常规文本字段的高度 textField.frame.size.height = 60 但是,如果我将此代码实现到我的UIAlertController中的textfield,它将不起作用。我还尝试将键盘更改为支持ASCII码的键盘,但在我运行应用程序后,它不会更改键盘。我好像错过了什么 这是我的警报控制器的代码 let alertController = UIAlertController(title: "Write Comment", message: "T
textField.frame.size.height = 60
但是,如果我将此代码实现到我的UIAlertController
中的textfield,它将不起作用。我还尝试将键盘更改为支持ASCII码的键盘,但在我运行应用程序后,它不会更改键盘。我好像错过了什么
这是我的警报控制器的代码
let alertController = UIAlertController(title: "Write Comment", message: "Tell us why you are not satisfied", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Send", style: .default, handler: { alert -> Void in
let textField = alertController.textFields![0] as UITextField
textField.frame.size.height = 60
textField.keyboardType = .asciiCapable
let commentDefect = textField.text ?? ""
self.sendComment(defectID: defectID, comment: commentDefect)
}))
alertController.view.tintColor = UIColor(red: 0/255, green: 129/255, blue: 58/255, alpha: 1)
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in
textField.placeholder = ""
})
self.present(alertController, animated: true, completion: nil)
结果如下:
似乎高度仍然在17左右。这里出了什么问题?您添加了以下代码:-
alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in
textField.placeholder = ""
let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 120)
textField.addConstraint(heightConstraint)
})
希望对你有帮助
它是重复的您添加了以下代码:-
alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in
textField.placeholder = ""
let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 120)
textField.addConstraint(heightConstraint)
})
let alertController = UIAlertController(title: "Write Comment", message: "Tell us why you are not satisfied", preferredStyle: .alert)
alertController.addTextField { (textField:UITextField) in
let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: yourHeightValue)
textField.placeholder = ""
textField.addConstraint(heightConstraint)
textField.keyboardType = .asciiCapable
}
alertController.addAction(UIAlertAction(title: "Send", style: .default, handler: { (alert) in
let commentDefect = alertController.textFields?.first?.text ?? ""
self.sendComment(defectID: defectID, comment: commentDefect)
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alertController.view.tintColor = UIColor(red: 0.0/255.0, green: 129.9/255.0, blue: 58.0/255.0, alpha: 1.0)
self.present(alertController, animated: true, completion: nil)
希望对你有帮助
它是重复的这是答案这是答案
let alertController = UIAlertController(title: "Write Comment", message: "Tell us why you are not satisfied", preferredStyle: .alert)
alertController.addTextField { (textField:UITextField) in
let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: yourHeightValue)
textField.placeholder = ""
textField.addConstraint(heightConstraint)
textField.keyboardType = .asciiCapable
}
alertController.addAction(UIAlertAction(title: "Send", style: .default, handler: { (alert) in
let commentDefect = alertController.textFields?.first?.text ?? ""
self.sendComment(defectID: defectID, comment: commentDefect)
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alertController.view.tintColor = UIColor(red: 0.0/255.0, green: 129.9/255.0, blue: 58.0/255.0, alpha: 1.0)
self.present(alertController, animated: true, completion: nil)