change UIAlertcontroller background Color

前端 未结 7 925
孤城傲影
孤城傲影 2021-02-02 15:09

Ok so I have this alert that I am using and I want the background of it to be black not grey like it is. I have managed to change the colour of the text for the title and the me

7条回答
  •  暖寄归人
    2021-02-02 15:26

    Swift 4.1 :

    This is the best way works for me :

    func testAlert(){
        let alert = UIAlertController(title: "Let's See ..",message: "It Works!", preferredStyle: .alert)
        let dismissAction = UIAlertAction(title: "Dismiss", style: .default, handler: nil)
    
        // Accessing alert view backgroundColor :
        alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = UIColor.green
    
        // Accessing buttons tintcolor :
        alert.view.tintColor = UIColor.white
    
        alert.addAction(dismissAction)
        present(alert, animated: true, completion:  nil)
    }
    

提交回复
热议问题