How to display activity indicator in center of UIAlertController?

后端 未结 13 984
猫巷女王i
猫巷女王i 2020-12-08 05:18

I currently have a UIAlertController being displayed on the screen. The view of the alert should only display 2 elements, a title and a UIActivityIndicato

相关标签:
13条回答
  • 2020-12-08 05:44

    Swift 5.0 solution

    let alert = UIAlertController(title: "Sender ...", message: nil, preferredStyle: .alert)
    let activityIndicator = UIActivityIndicatorView(style: .gray)
    activityIndicator.translatesAutoresizingMaskIntoConstraints = false
    activityIndicator.isUserInteractionEnabled = false
    activityIndicator.startAnimating()
    
    alert.view.addSubview(activityIndicator)
    alert.view.heightAnchor.constraint(equalToConstant: 95).isActive = true
    
    activityIndicator.centerXAnchor.constraint(equalTo: alert.view.centerXAnchor, constant: 0).isActive = true
    activityIndicator.bottomAnchor.constraint(equalTo: alert.view.bottomAnchor, constant: -20).isActive = true
    
    present(alert, animated: true)
    
    0 讨论(0)
提交回复
热议问题