xcode - 如何使按钮在 alertController 中可见?
问题描述
我在弄清楚这一点时遇到了一些问题。我在警报控制器中看不到取消按钮和确定按钮,它位于文本视图后面。我使用文本视图,以便有更多的空间可以写。
这是我写的代码。
@IBAction func appltyButton(_ sender: Any) {
let alertController = UIAlertController(title: "Write your message.", message: nil, preferredStyle: .alert)
let rect = CGRect(x: 15, y: 50, width: 240, height: 150.0)
let textView = UITextView(frame: rect)
textView.font = UIFont(name: "Helvetica", size: 15)
textView.textColor = UIColor.lightGray
textView.backgroundColor = UIColor.white
textView.layer.borderColor = UIColor.lightGray.cgColor
textView.layer.borderWidth = 1.0
textView.text = "Enter message here"
textView.delegate = self as? UITextViewDelegate
alertController.view.addSubview(textView)
let okAction = UIAlertAction(title: "OK", style: .default, handler: self.okHandler)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true)
我希望能够看到按钮。谢谢
解决方案
用于.addTextField
向警报添加文本字段。简单地添加子视图并不像您想要的那样工作,并且也明确不鼓励:
重要的
UIAlertController 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。
或者,使用允许更多自定义的许多警报库之一,例如SDCAlertView。
推荐阅读
- asp.net-mvc - Azure Active Directory - 我们无法让您登录。请重试
- django - Django 错误:/new_bid/1 处的 ValueError 无法分配“1”:“Bid.listingid”必须是“列表”实例
- javascript - 尝试更改为 onChange 后,onEdit 触发器中断
- pine-script - Pinescript 没有在较短的时间范围图表上绘制更高分辨率的计算。怎么解决
- amazon-web-services - 在 GraphMappingConfig 中自动填充顶点属性
- sql - 找到那些在不同行中具有不同值的列?
- c# - 需要发送FIN/ACK
- python - 围绕另一个点旋转一个点会产生意想不到的结果
- wpf - 可以在没有 IoC 的情况下使用 MvvmCross Messenger 吗?
- javascript - Express Node.js react 集成(拒绝应用样式和加载资源失败)