【发布时间】:2017-06-17 06:51:32
【问题描述】:
我正在尝试使用操作表样式创建 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];
这给了我以下结果: Link
我访问过How to change the background color of the UIAlertController? ,但没有一个解决方案为“取消”按钮的背景提供自定义颜色。
任何帮助将不胜感激!
【问题讨论】:
-
你想改变取消按钮的背景颜色吗?
-
查看我的编码 我将取消按钮颜色更改为深灰色。
-
我希望取消按钮具有深灰色背景色和白色文本。您的代码似乎没有这样做,而是相反:您的取消按钮的背景颜色是白色,而您的文本颜色是灰色
标签: ios objective-c uialertcontroller