My question is similar to this where I couldn't find the answer.
UIAlertController change background color of Cancel button for action sheet 这alertController with white borders 我希望带有actionStyle的取消按钮为"取消"并且背景应该是不同的颜色(默认情况下它将是白色)。如何更改“取消”按钮的背景颜色。我不想将actionStyle更改为默认值。有没有其他方法来实现这一目标? 这是我的代码
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)
}