更新时间:2023-02-04 12:03:00
A UIAlertController
来自 UIViewController
的子类.因此,UIAlertController
包含一个可以修改的视图.因此,要向警报添加标签,您可以这样做:
A UIAlertController
sub-classes from UIViewController
. Because of this, a UIAlertController
contains a view which can be modified. So, to add a label to the alert, you could do this:
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
label.text = "Text"
alert.view.addSubview(label)
但是,您应该记住文档中的说明:
UIAlertController 类旨在按原样使用,而不是支持子类化.此类的视图层次结构是私有的,并且不得修改.
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.