我正在使用新的UIAlertController来显示警报.我有这个代码:
// nil titles break alert interface on iOS 8.0, so we'll be using empty strings
UIAlertController *alert = [UIAlertController alertControllerWithTitle: title == nil ? @"": title message: message preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle: cancelButtonTitle style: UIAlertActionStyleCancel handler: nil];
[alert addAction: defaultAction];
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootViewController presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
现在我想更改标题和消息字体,颜色,大小等.什么是最好的方法呢?
编辑: 我应该插入整个代码.我为UIView创建了一个类别,我可以为iOS版本显示正确的警报.
@implementation UIView (AlertCompatibility)
+( void )showSimpleAlertWithTitle:( NSString * )title
message:( NSString * )message
cancelButtonTitle:( NSString * )cancelButtonTitle
{
float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue]; …Run Code Online (Sandbox Code Playgroud) 我想更改UIAlertView的背景颜色,但这似乎没有颜色属性.
好吧,我有这个警告,我正在使用它,我希望它的背景是黑色而不是灰色的样子.我已设法更改标题和消息的文本颜色,但不更改背景颜色.那么我想要的颜色.我已将其更改为绿色蓝色和白色,但不是黑色.当我尝试将其更改为黑色时,它会变为灰色.任何建议都会有所帮助并受到赞赏.我试过这里如何更改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) …Run Code Online (Sandbox Code Playgroud) 我正在使用new UIAlertController为我的应用程序实现各种选项菜单.我试图获得与UIAlertController我的应用程序其余部分的主题相匹配的背景颜色.我的应用程序的主题非常简单,包含工具栏和导航栏的蓝色/灰色背景颜色的白色文本,如下所示:

但是,我在尝试让我UIAlertController遵守这个主题时遇到了一些麻烦.我进行了以下两次调用来设置文本和背景颜色:
uiAlertController.view.backgroundColor = UIColor(red: CGFloat(.17255), green: CGFloat(.24314), blue: CGFloat(.31373), alpha: CGFloat(1.0))
uiAlertController.view.tintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)
这改变了UIAlertController如下所示:

文本已从默认的蓝色系统颜色更改为白色,但背景颜色不正确.我也尝试修改指定opacity(uiAlertController.view.opaque = true),但这也没有帮助.如何设置背景颜色以使其与导航栏和工具栏匹配?谢谢
我正在用于UIAlertController一些操作。
但我不太喜欢动作组视图中的模糊视图效果(请参见下面的屏幕截图)。
我正在尝试消除这种模糊效果。我在网上做了一些研究,但找不到任何UIAlertController可以消除这种模糊效果的 API。另外,根据他们的苹果文档:
UIAlertController 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。
我看到 Instagram 也消除了这种模糊的视图效果:
我找到删除它的唯一方法是通过UIAlertController.
extension UIAlertController {
@discardableResult private func findAndRemoveBlurEffect(currentView: UIView) -> Bool {
for childView in currentView.subviews {
if childView is UIVisualEffectView {
childView.removeFromSuperview()
return true
} else if String(describing: type(of: childView.self)) == "_UIInterfaceActionGroupHeaderScrollView" {
// One background view is broken, we need to make sure it's white.
if let brokenBackgroundView = childView.superview {
// Set broken brackground view to a darker white …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用动作表样式创建UIAlertController,但我想将背景颜色更改为灰色.我已经能够找到一种方法来改变UIAlertController的背景颜色,但不能找到取消按钮."取消"按钮是独立的,保持白色.
这是我现在的代码:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Option 1" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Option 2" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Option 3" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
UIView *firstSubview = alert.view.subviews.firstObject;
UIView *alertContentView = firstSubview.subviews.firstObject;
for (UIView *subSubView in alertContentView.subviews) {
subSubView.backgroundColor = [UIColor darkGrayColor]; // Here you change background
}
alert.view.tintColor = [UIColor whiteColor];
[self.controller presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这给了我以下结果: 链接
我已经访问过如何更改UIAlertController的背景颜色? 但是没有一个解决方案具有"取消"按钮背景的自定义颜色.
任何帮助,将不胜感激!