【问题标题】:How I can add custom elements to UIAlertController? [duplicate]如何将自定义元素添加到 UIAlertController? [复制]
【发布时间】:2019-03-22 16:01:10
【问题描述】:

请告诉我如何发出如图所示的警报?

我添加了这段代码。但是如何才能将元素放置在正确的位置呢?

alert = UIAlertController(title: NSLocalizedString("AttendUpload", comment: "Идет загрузка файла, пожалуйста подождите"), message: "", preferredStyle: .alert)


    uploadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
    uploadingIndicator!.hidesWhenStopped = true
    uploadingIndicator!.style = UIActivityIndicatorView.Style.whiteLarge
    uploadingIndicator!.startAnimating() 

    uploadingPercentage = UILabel(frame: CGRect(x: 10, y: 10, width: 200, height: 50))
    uploadingPercentage?.text = "Загружено 0%"//NSLocalizedString("Uploaded", comment: "Загружено") + "0 %"
    uploadingPercentage?.font = UIFont.preferredFont(forTextStyle: .body)
    uploadingPercentage?.textColor = UIColor.red

    self.alert!.view.addSubview(uploadingIndicator!)
    self.alert!.view.addSubview(uploadingPercentage!)

    present(alert!, animated: true, completion: nil)

Alert picture

【问题讨论】:

    标签: ios swift uiview uialertcontroller


    【解决方案1】:

    您不应该尝试这样做。来自docs

    UIAlertController 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。

    您应该创建自己的视图控制器。

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多