0

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)
IOS Rocks
  • 2,127
  • 2
  • 21
  • 24
  • First refer below link https://stackoverflow.com/questions/30287400/change-uiactionsheet-buttons-background-color-and-button-font – Shah Nilay Jul 28 '17 at 10:59

1 Answers1

0

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

R.Chauhan
  • 51
  • 1