如何改变UIAlertController的色彩颜色?

我可以更改UIAlertController颜色吗? 标准颜色是蓝色。 它和标准的iOS应用程序非常接近。 如果它是可定制的? 我怎样才能改变这个颜色? 例如一个button的颜色。

谢谢!

您可以更改底层视图的tintColor ,但由于iOS 9( https://openradar.appspot.com/22209332 )中引入的已知错误,tintColor被应用程序窗口的tintColor覆盖。

你可以:

  1. 更改AppDelegate中的应用程序tintColor

     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { self.window.tintColor = UIColor.redColor() return true } 
  2. 重新应用完成块的颜色。

     self.presentViewController(alert, animated: true, completion: {() -> Void in alert.view.tintColor = UIColor.redColor() }) 

只需更改底层视图的tintColor。

 [alertController.view setTintColor:[UIColor yellowColor]]; 

在Swift中,你可以做这样的事情:

 let alert = UIAlertController(title: "Alert", message: "This is an alert.", preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) alert.view.tintColor = UIColor.redColor() self.presentViewController(alert, animated: true, completion: nil) 

Swift 4Xcode 9.2中

 let alertView = UIAlertController(title: "", message: "", preferredStyle: .alert) alertView.addAction(UIAlertAction(title: "CONFIRM", style: .default, handler: { (alertAction) -> Void in //my logic })) alertView.addAction(UIAlertAction(title: "CANCEL", style: .default, handler: nil)) alertView.view.tintColor = UIColor.init(red: 45.0/255.0, green: 187.0/255.0, blue: 135.0/255.0, alpha: 1.0) present(alertView, animated: true, completion: nil) 

在你的UIAllertController中添加一行:

 alert.view.tintColor = UIColor.black