How to change UIAction sheet Cancel button background color

165 Views Asked by At

I was trying to change the background color of UIAction sheet "Cancel" button but it doesn't work. Here is my code snippet

if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first {
    for innerView in alertContentView.subviews {
        innerView.backgroundColor =  UIColor.red//StyleKit.popoverDefaultBackgroundColor
        //drop shadow
        innerView.layer.masksToBounds = false
        innerView.layer.shadowOpacity = 0.8
    }
}
let subview = alertController.view.subviews.last! as UIView
let alertContentView = subview.subviews.last! as UIView
alertContentView.backgroundColor = UIColor.black

let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel)

alertController.addAction(changeAction)
alertController.addAction(cancelAction)
1

There are 1 best solutions below

0
On

Try this - let subView = alertController.view.subviews.first! Var alertContentView = subView.subviews.first! alertContentView.backgroundColor = UIColor.black alertContentView.layer.cornerRadius = 5