0

How do i set the dismissOnOutsideTapped to false? I am trying to prevent the user from dismissing the AlertController until the Ok button is tapped

myView.translatesAutoresizingMaskIntoConstraints = false
myView.heightAnchor.constraint(equalToConstant: 100).isActive = true

    let attributedString = NSAttributedString(string: title, attributes: [
        NSAttributedStringKey.foregroundColor : #colorLiteral(red: 0.8226075768, green: 0.2890471816, blue: 0.2390623093, alpha: 1)
        ])
    let alert = AlertController(title: "", message: "")
    alert.setValue(attributedString, forKey: "attributedTitle")


let OkAction: AlertAction = AlertAction(title: "OK", style: .preferred) { (action) in
   MyCode......
}
alert.addAction(OkAction)
alert.contentView.addSubview(myView)
myView.leftAnchor.constraint(equalTo: alert.contentView.leftAnchor).isActive = true
myView.rightAnchor.constraint(equalTo: alert.contentView.rightAnchor).isActive = true
myView.centerXAnchor.constraint(equalTo: alert.contentView.centerXAnchor).isActive = true
myView.topAnchor.constraint(equalTo:alert.contentView.topAnchor, constant: -25).isActive = true
content.bottomAnchor.constraint(equalTo: alert.contentView.bottomAnchor).isActive = true



alert.view.tintColor = #colorLiteral(red: 0.8226075768, green: 0.2890471816, blue: 0.2390623093, alpha: 1)
alert.present()

1 Answers1

0

You can use AlertBehaviors to disable outside touches. Something like this.

let alert = AlertController(title: "", message: "")
alert.behaviors = AlertBehaviors.init(rawValue: 0) 

For details see AlertBehaviors in github docs.

Bilal
  • 18,478
  • 8
  • 57
  • 72