这就是我现在要做的事情:
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,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}解决方法 试试这个
Swift2及以下
let subvIEw :UIVIEw = alert.vIEw.subvIEws. first! as UIVIEwlet alertContentVIEw = subvIEw.subvIEws. first! as UIVIEwalertContentVIEw.backgroundcolor = UIcolor.blackcolor()
目标-C
UIVIEw *subVIEw = alertController.vIEw.subvIEws.firstObject; //firstObjectUIVIEw *alertContentVIEw = subVIEw.subvIEws.firstObject; //firstObject[alertContentVIEw setBackgroundcolor:[UIcolor darkGraycolor]];alertContentVIEw.layer.cornerRadius = 5;
更新的答案迅速3及以上
let alert = UIAlertController(Title: "valIDate",message: "Check the process",preferredStyle: .alert) let dismissAction = UIAlertAction(Title: "dismiss",style: .destructive,handler: nil) alert.addAction(dismissAction) self.present(alert,completion: nil) // change the background color let subvIEw = (alert.vIEw.subvIEws.first?.subvIEws.first?.subvIEws.first!)! as UIVIEw subvIEw.layer.cornerRadius = 1 subvIEw.backgroundcolor = UIcolor(red: (195/255.0),green: (68/255.0),blue: (122/255.0),Alpha: 1.0)
产量
苹果手机
iPad的
总结以上是内存溢出为你收集整理的ios – 更改UIAlertcontroller背景颜色全部内容,希望文章能够帮你解决ios – 更改UIAlertcontroller背景颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)