change UIAlertcontroller Hintergrundfarbe
Okay, ich habe diese Warnung, die ich verwende, und ich möchte, dass der Hintergrund schwarz und nicht grau ist. Ich habe es geschafft, die Farbe des Texts für den Titel und die Nachricht zu ändern, aber nicht die Hintergrundfarbe. Nun zu der gewünschten Farbe, die ich will. Ich habe es in Grün, Blau und Weiß geändert, aber nicht in Schwarz. Wenn ich versuche, es in Schwarz zu ändern, wird es grau. Irgendwelche Vorschläge helfen und werden geschätzt. Ich habe das hier versuchtWie ändere ich die Hintergrundfarbe des UIAlertControllers? und so bin ich zu dem gekommen, wo ich jetzt bin.
Hier ist was ich jetzt los bin:
func showAlert(title:String, message:String) {
//Set up for the title color
let attributedString = NSAttributedString(string: title, attributes: [
NSFontAttributeName : UIFont.systemFontOfSize(15), //your font here,
NSForegroundColorAttributeName : UIColor.whiteColor()
])
//Set up for the Message Color
let attributedString2 = NSAttributedString(string: message, attributes: [
NSFontAttributeName : UIFont.systemFontOfSize(15), //your font here,
NSForegroundColorAttributeName : UIColor.whiteColor()
])
let alert = UIAlertController(title: title,message: message, preferredStyle: .Alert)
alert.setValue(attributedString, forKey: "attributedTitle")
alert.setValue(attributedString2, forKey: "attributedMessage")
//alert.view.tintColor = UIColor.whiteColor()
let dismissAction = UIAlertAction(title: "Dismiss", style: .Destructive, handler: nil)
alert.addAction(dismissAction)
self.presentViewController(alert, animated: true, completion: nil)
//set the color of the Alert
let subview = alert.view.subviews.first! as UIView
let alertContentView = subview.subviews.first! as UIView
alertContentView.backgroundColor = UIColor.blackColor()
//alertContentView.backgroundColor = UIColor.greenColor()
//Changes is to a grey color :(
/*
alertContentView.backgroundColor = UIColor(
red: 0,
green: 0,
blue: 0,
alpha: 1.0)
//Also another Grey Color Not batman black
*/
//alertContentView.backgroundColor = UIColor.blueColor()
//turns into a purple
}