UIAlertController更改我的按钮颜色

时间:2015-01-19 13:45:48

标签: ios uialertcontroller

我这样叫UIAlertController

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title"
                                                                         message:@"msg"
                                                                  preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Accept" 
                                                   style:UIAlertActionStyleDefault 
                                                 handler:^(UIAlertAction *action) {/*...*/}
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                       style:UIAlertActionStyleCancel 
                                                     handler:^(UIAlertAction *action) {/*...*/}];

[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];

我的问题是,当显示UIAlertController时,它会将导航栏的颜色从黄色变为白色,系统的灯光信息按钮从蓝色变为灰色(看起来不错,看起来很像像一个想要“使屏幕看起来不那么多彩”的效果)。如果用户在此时按下主页按钮,应用程序将在应用程序再次从背景进入时保留该颜色(这会将用户带到登录屏幕,该屏幕具有白色/灰色)。

这个问题有解决方法吗?

2 个答案:

答案 0 :(得分:3)

自iOS7以来,在显示警报视图时,视图已提供不同的行为:

  

当出现警报或操作表时,iOS 7会自动调暗   它背后的意见色彩。为了应对这种颜色变化,a   应该在渲染中使用tintColor的自定义视图子类   覆盖tintColorDidChange以在适当时刷新渲染。

如上所述,您应覆盖tintColorDidChange,请检查here

答案 1 :(得分:2)

这是故意的,并且在出现任何警报时发生。这是因为在显示警报时,视图的交互式部分(例如按钮)不是交互式的。

在显示提醒时,下方视图的tintAdjustmentMode将更改为UIViewTintAdjustmentModeDimmed。您可以实施tintColorDidChange来回应此更改,但在我看来,您不应该这样做。