0

In my Swift code below the goal would be that if the user hits the best friend button once it turns green and the 2nd time it reverts back to the original color. Green would signify true and no color would signify false. I don't know how to change the color on alert action buttons but I assume it's possible. Right now every time I hit the Best friend button it dismisses the action sheet. I want it to hold a color green and not dismiss the action sheet.

@objc func addSong(_ sender: UIBarButtonItem) {
    var titleTextField = UITextField()
    var releaseDateTextField = UITextField()
    
    let alert = UIAlertController(title: "Enter name", message: "", preferredStyle: .alert)
    let createAction = UIAlertAction(title: "Create", style: .default) { [self] (action) in 
    }
    
    alert.addTextField { (alertTextField) in
        titleTextField = alertTextField
    }
    
    let cancelAction = UIAlertAction(title: "Cancel", style: .destructive) { (action) in
        self.dismiss(animated: true, completion: nil)
    }
    
    let bestFiend = UIAlertAction(title: "Best Feind", style: .default) { (action) in
        releaseDateTextField.backgroundColor = .red
        //self.dismiss(animated: true, completion: nil)
    }
    
    alert.addAction(bestFiend)
    alert.addAction(createAction)
    alert.addAction(cancelAction)
  
    present(alert, animated: true, completion: nil)
}
HangarRash
  • 7,314
  • 5
  • 5
  • 32
Max Madill
  • 39
  • 6
  • You can't. All actions dismiss the alert. That can't be changed. – HangarRash Aug 27 '23 at 22:07
  • how could I do something like this in action alert. Could I use a switch? – Max Madill Aug 27 '23 at 22:10
  • 1
    No, UIAlertController does not support adding custom views. Create your own alert style view that supports the functionality you want. Search on "custom UIAlertController` for ideas to get you started. – HangarRash Aug 27 '23 at 22:12

0 Answers0