How to insert UILabel after UITextField in UIAlertController

别等时光非礼了梦想. 提交于 2019-12-11 03:17:23

问题


I have a UIAlertController of .alert style with message text. I have inserted a UITextFiled in it with addTextField(.... and now I want a string of text below it. I assume I need a UILabel but how do I insert it?


回答1:


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)

However, you should keep in mind what is 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.



来源:https://stackoverflow.com/questions/44049459/how-to-insert-uilabel-after-uitextfield-in-uialertcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!