0
My question is similar to this where I couldn't find the answer.

UIAlertController change background color of Cancel button for action sheet and this alertController with white borders I want the cancel button with actionStyle as "Cancel" and the background should be of different colour(By default it will be white). How to change the background colour of Cancel button. I don't want to change the actionStyle to default. Is there any other way to achieve this? This is my code

   func showActionSheet(_ changeAction: UIAlertAction) {
    let alertController = UIAlertController(title: "", message: "Are you sure".localize(), preferredStyle: .actionSheet)
    alertController.view.tintColor = UIColor.green
    if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first {
        for innerView in alertContentView.subviews {
            innerView.backgroundColor = UIColor.red
        }
    }
    let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
        self.doneButton.isEnabled = true
    }
    alertController.addAction(changeAction)
    alertController.addAction(cancelAction)
    self.present(alertController, animated: true)
}
vinny
  • 360
  • 3
  • 10

1 Answers1

0

It's possible to change it using UIAppearance and a little hack. See my answer here

ipaboy
  • 257
  • 4
  • 8