ios - 如何在 UIAlertController 中设置 UITextField 的高度?
问题描述
我知道通过使用此代码以编程方式设置常规文本字段的高度
textField.frame.size.height = 60
但是,如果我将此代码实现到我的文本字段中UIAlertController
,它就不起作用。我也尝试将键盘更改为支持 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)
})
希望对您有所帮助。
这是重复的
推荐阅读
- java - 枚举语法解释
- azure - MSB4126 指定的解决方案配置“Release2018, Release2019|Any CPU”无效
- javascript - 在 Angular 中创建喜欢/不喜欢的指令
- python - 异构 Numpy 数组的记录数据类型
- java - 如何将图像放入邮件标题(Spring Boot)?
- gpu - OpenCL 和 Radeon R4 集成显卡
- ios - 在 iOS Swift 应用程序关闭时如何刷新 JWT 令牌?
- mysql - Sequelize - 模型和迁移
- uno-platform - 目前是否有适用于 Uno 平台 WASM 应用程序的“离线”客户端唯一部署选项?
- python - Pandas - 添加列与行值应用条件相对于当前行