如何更改UIAlertController的背景颜色? [英] How to change the background color of the UIAlertController?
问题描述
由于UIActionSheet在iOS 8中的奇怪行为,我已经将UIAlertController与UIAction一起实现为按钮。我想改变UIAlertController的整个背景。但是我找不到任何办法。
Due to strange behavior of UIActionSheet in iOS 8, I have implemented UIAlertController with UIAction as buttons in it. I would like to change the entire background of the UIAlertController. But I can't find any ways to do it.
甚至尝试过,
actionController.view.backgroundColor = [UIColor blackColor];
但是没有帮助我。关于这方面的任何意见都会很明显。
But didn't help me out. Any inputs on this regard will be appreciable.
提前致谢。
推荐答案
你必须深入了解一些观点:
You have to step some views deeper:
let subview = actionController.view.subviews.first! as UIView
let alertContentView = subview.subviews.first! as UIView
alertContentView.backgroundColor = UIColor.blackColor()
也许你想保留原始角半径:
And maybe you want to keep original corner radius:
alertContentView.layer.cornerRadius = 5;
抱歉Swifting但我不熟悉Objective -C。我希望它类似。
Sorry for the "Swifting" but i'm not familiar with Objective-C. I hope that's similar.
当然,更改动作的标题颜色也很重要。不幸的是我不知道,如何分别设置动作的颜色。但是,这是如何更改所有按钮文本颜色:
Of course it's also important to change the title color of the actions. Unfortunately I don't know, how to set the color of actions separately. But this is, how you change all button text colors:
actionController.view.tintColor = UIColor.whiteColor();
编辑:
角落半径自从这个答案发布以来, UIAlertController 已经改变了!替换它:
The corner radius of the UIAlertController has changed since this answer's been posted! Replace this:
alertContentView.layer.cornerRadius = 5;
到此:
actionContentView.layer.cornerRadius = 15
这篇关于如何更改UIAlertController的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!