How to change UIAlertController button text colour in iOS9?

后端 未结 14 1357
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 16:16

The question is similar to iOS 8 UIActivityViewController and UIAlertController button text color uses window's tintColor but in iOS 9.

I have a UIAlertControlle

14条回答
  •  遥遥无期
    2020-12-15 16:43

    swift3

    Tried to use UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = MyColor but this prevents other items unrelated to the UIAlertController from tintColor configuration. I saw it while trying to change the color of navigation bar button items.

    I switched to an extension (based on Mike Taverne's response above) and it works great.

    extension UIAlertController {
    
    override open func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
    
        //set this to whatever color you like...
        self.view.tintColor = MyColor
    }
    }
    

提交回复
热议问题