如何在 UIAlertController 中的 UITextField 之后插入 UILabel

How to insert UILabel after UITextField in UIAlertController

我有 UIAlertController.alert 风格的消息文本。我在其中插入了一个 UITextFiledaddTextField(....,现在我想要在它下面有一串文本。我假设我需要一个 UILabel 但我该如何插入它?

来自 UIViewControllerUIAlertController 子 类。因此,UIAlertController 包含一个可以修改的视图。因此,要为警报添加标签,您可以这样做:

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
label.text = "Text"
alert.view.addSubview(label)

但是,你应该记住什么是 said in the docs:

The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.