UIAlertController custom font, size, color

后端 未结 25 1974
遥遥无期
遥遥无期 2020-11-22 09:06

I am using new UIAlertController for showing alerts. I have this code:

// nil titles break alert interface on iOS 8.0, so we\'ll be using empty strings
UIAle         


        
25条回答
  •  [愿得一人]
    2020-11-22 09:39

    You can change the button color by applying a tint color to an UIAlertController.

    On iOS 9, if the window tint color was set to a custom color, you have to apply the tint color right after presenting the alert. Otherwise the tint color will be reset to your custom window tint color.

    // In your AppDelegate for example:
    window?.tintColor = UIColor.redColor()
    
    // Elsewhere in the App:
    let alertVC = UIAlertController(title: "Title", message: "message", preferredStyle: .Alert)
    alertVC.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
    alertVC.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
    
    // Works on iOS 8, but not on iOS 9
    // On iOS 9 the button color will be red
    alertVC.view.tintColor = UIColor.greenColor()
    
    self.presentViewController(alert, animated: true, completion: nil)
    
    // Necessary to apply tint on iOS 9
    alertVC.view.tintColor = UIColor.greenColor()
    

提交回复
热议问题