Ok, więc mam ten alert, którego używam i chcę, aby jego tło było czarne, a nie szare, tak jak jest. Udało mi się zmienić kolor tekstu tytułu i wiadomości, ale nie kolor tła. Dobrze do pożądanego koloru, który chcę. Zmieniłem go na zielony, niebieski i biały, ale nie czarny. Kiedy próbuję zmienić kolor na czarny, zmienia kolor na szary. Wszelkie sugestie pomogą i zostaną docenione. Próbowałem tego tutaj How to change the background color of the UIAlertController? i tak właśnie dotarłem tam, gdzie teraz jestem.zmiana koloru tła UIAlertcontroller Kolor
Oto co mam zamiar teraz:
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
}
@ LucaDavanzo, tak naprawdę mam do tego miejsca. Jeśli spojrzysz na mój kod, to jest dokładnie taki sam, jak jedna z sugestii. – MNM