UIAlertController 改变了我的按钮颜色
UIAlertController changes my button colors
我这样称呼 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
时,它会将我的导航栏的颜色从黄色更改为白色,并将系统的灯光信息按钮从蓝色更改为灰色(看起来并没有错,它更像是一个想要的 "make the screen look less colorful" 效果)。如果用户在那一刻按下主页按钮,应用程序将在应用程序再次从后台进入时保持该颜色(这会将用户带到具有 white/gray 颜色的登录屏幕)。
这个问题有解决方法吗?
自 iOS7 起,视图在显示警报视图时具有不同的行为:
When an alert or action sheet appears, iOS 7 automatically dims the
tint color of the views behind it. To respond to this color change, a
custom view subclass that uses tintColor in its rendering should
override tintColorDidChange to refresh the rendering when appropriate.
如所写,您应该覆盖 tintColorDidChange
,检查 here
这是有意的,出现任何警报时都会发生。这是因为在显示警报时,视图的交互部分(例如按钮)不是交互的。
显示警报时,下方视图的 tintAdjustmentMode
将更改为 UIViewTintAdjustmentModeDimmed
。您可以实施 tintColorDidChange
来响应此更改,但我认为您不应该这样做。
我这样称呼 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
时,它会将我的导航栏的颜色从黄色更改为白色,并将系统的灯光信息按钮从蓝色更改为灰色(看起来并没有错,它更像是一个想要的 "make the screen look less colorful" 效果)。如果用户在那一刻按下主页按钮,应用程序将在应用程序再次从后台进入时保持该颜色(这会将用户带到具有 white/gray 颜色的登录屏幕)。
这个问题有解决方法吗?
自 iOS7 起,视图在显示警报视图时具有不同的行为:
When an alert or action sheet appears, iOS 7 automatically dims the tint color of the views behind it. To respond to this color change, a custom view subclass that uses tintColor in its rendering should override tintColorDidChange to refresh the rendering when appropriate.
如所写,您应该覆盖 tintColorDidChange
,检查 here
这是有意的,出现任何警报时都会发生。这是因为在显示警报时,视图的交互部分(例如按钮)不是交互的。
显示警报时,下方视图的 tintAdjustmentMode
将更改为 UIViewTintAdjustmentModeDimmed
。您可以实施 tintColorDidChange
来响应此更改,但我认为您不应该这样做。