我可以更改UIAlertController
的顏色嗎?標準顏色是藍色。它非常接近標準的iOS應用程序。如果它是可定製的?我該如何改變顏色?例如一個按鈕的顏色。如何更改UIAlertController的色彩顏色?
謝謝!
我可以更改UIAlertController
的顏色嗎?標準顏色是藍色。它非常接近標準的iOS應用程序。如果它是可定製的?我該如何改變顏色?例如一個按鈕的顏色。如何更改UIAlertController的色彩顏色?
謝謝!
你可以只改變基本觀點的tintColor
,然而,由於iOS的9(https://openradar.appspot.com/22209332)推出了一個已知的bug,在tintColor由應用程序窗口的tintColor
覆蓋。
您可以:
變化在AppDelegate中的應用tintColor
。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
self.window.tintColor = UIColor.redColor()
return true
}
重新應用完成塊中的顏色。
self.presentViewController(alert, animated: true, completion: {() -> Void in
alert.view.tintColor = UIColor.redColor()
})
只需更改底層視圖的tintColor。
[alertController.view setTintColor:[UIColor yellowColor]];
這實際上是可行的 – Jargen89
在斯威夫特,你可以做這樣的事情:
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)
正如@guidev所說的,有一個錯誤可以阻止提醒控制器履行你在其上設置的'tintColor'。 – NRitH
看起來這個bug可能已經修復了。我剛剛在Xcode 9.2(9C40b) - iOS 11中測試過,現在看起來工作正常。 –
在斯威夫特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)
在UIAllertController添加一行:
alert.view.tintColor = UIColor.black
謝謝!工作很好。 – Beginner
是的,很棒! – Bill
alertController.view.tintColor = [UIColor yellowColor];對我來說工作得很好 – Jargen89