UIAlertController背景色iOS10 [英] UIAlertController background color iOS10
问题描述
我为iOS9编写的代码非常有效:
Code that I wrote for iOS9, worked really well:
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Select source"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alert.view.backgroundColor = DARK_BLUE;
alert.view.tintColor = NEON_GREEN;
UIView *subview = alert.view.subviews.firstObject;
UIView *alertContentView = subview.subviews.firstObject;
alertContentView.backgroundColor = DARK_BLUE;
alertContentView.layer.cornerRadius = 10;
我的观点是UIAlertController
是从UIViewController
继承的,而UIViewController
具有可以更改的属性UIView
.这正在工作.现在,从UIViewController
继承的视图具有自己的子视图,即contentView显示为Alert.我可以在子视图数组中作为firstObject访问它.现在,为什么发送背景色的消息不再起作用?有人知道一些新的解决方案吗?
My point of view is that UIAlertController
is inheriting from UIViewController
, and UIViewController
have property UIView
that can be changed. And this is working. Now, that view inherited from UIViewController
have it's own subview that is contentView showed as Alert. I can access it as firstObject in array of subviews. Now, why message for sending background color isn't working anymore? Do anyone know some new solution?
推荐答案
对于遇到相同问题的每个人,我都找到了解决方案:
UIAlertController.view
包含一个子视图,该子视图仅是容器.
UIAlertController.view
contains one subview, that is only container.
该子视图包含一个子视图,该子视图包含两个自己的子视图,一个是容器,另一个是用于对其进行模糊处理的层.
That subview contains subview that contains two it's own subviews, one is container, and another is layer for blurring it.
因此,需要在循环中迭代这两个子视图并更改两个子视图的背景色.
So, it needs for in loop to iterate through that two subviews and change background color of both.
完整代码:
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Select source"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alert.view.tintColor = NEON_GREEN;
UIView *firstSubview = alert.view.subviews.firstObject;
UIView *alertContentView = firstSubview.subviews.firstObject;
for (UIView *subSubView in alertContentView.subviews) { //This is main catch
subSubView.backgroundColor = DARK_BLUE; //Here you change background
}
这篇关于UIAlertController背景色iOS10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!