2016-06-09 145 views

回答

9

你可以只改變基本觀點的tintColor,然而,由於iOS的9(https://openradar.appspot.com/22209332)推出了一個已知的bug,在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() 
    }) 
    
+0

謝謝!工作很好。 – Beginner

+0

是的,很棒! – Bill

+2

alertController.view.tintColor = [UIColor yellowColor];對我來說工作得很好 – Jargen89

2

只需更改底層視圖的tintColor。

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

這實際上是可行的 – Jargen89

3

在斯威夫特,你可以做這樣的事情:

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) 
+0

正如@guidev所說的,有一個錯誤可以阻止提醒控制器履行你在其上設置的'tintColor'。 – NRitH

+0

看起來這個bug可能已經修復了。我剛剛在Xcode 9.2(9C40b) - iOS 11中測試過,現在看起來工作正常。 –

2

斯威夫特4的Xcode 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) 
1

在UIAllertController添加一行:

alert.view.tintColor = UIColor.black