好吧,所以我有这个警报,我正在使用,我想它的背景是黑色的,而不是灰色的。我设法改变标题和信息的文字颜色,但不改变背景颜色。以及我想要的颜色。我已将其更改为绿色蓝色和白色,但不是黑色。当我尝试将它改为黑色时,它会变成灰色。任何建议都会有所帮助,值得赞赏。我在这里尝试了这个How to change the background color of the UIAlertController?,这就是我现在所处的位置。更改UIAlertcontroller背景颜色
这是我现在打算:
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这实际上是我如何到达这个位置。如果你看我的代码,它是完全相同的建议 – MNM