最近想要在项目更好的优化下UI 试着去改系统自带的UIAlertController的弹出框颜色 ,却发现只有自己写的才能修改颜色,而系统自动调用的却无论怎么做都无法修改。
UIAlertController *abc = [UIAlertControlleralertControllerWithTitle:@"800-820-8820"message:nilpreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ac1 = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction*_Nonnullaction) {
}];
[ac1 setValue:kMainBaseColorforKey:@"_titleTextColor"];
[abcaddAction:ac1];
self.view.tintColor=kMainBaseColor;
UIAlertAction*ac2 = [UIAlertActionactionWithTitle:@"呼叫"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction*_Nonnullaction) {
}];
[ac2setValue:kMainBaseColorforKey:@"_titleTextColor"];
[abcaddAction:ac2];
[selfpresentViewController:abcanimated:YEScompletion:^{
}];
这是自己写的UIAlertController。使用的KVC模式去修改的UIAlertAction的字体颜色 这个方法是可行的。
而系统自动调用的却无法更改, 想使用RunTime去修改 却对RunTime机制还是不够了解。唉!
最后想的是如果能获取到这个UIAlertController 那么不就可以去遍历所有的子控件来修改赋值吗? 想到就去做。结果却发现。。。
手动调用UIAlertController这个是自己写的UIAlertController 了就是上面的代码。 这种方式调用出来的是可以看到的 也是嵌入在app里面的。 然而 系统的却不是。
NSString * callString =[NSString stringWithFormat:@"tel://800-820-8820"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callString] options:@{}completionHandler:nil];
这种方法在iOS10.2系统会自动调用UIAlertController
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:callString]];
这种调用方法在iOS10以下的系统中调用拨打电话功能都是直接调用的 并不会弹出UIAlertController
系统调用UIAlertController手机截图 系统调用UIAlertController Xcode从这个图层上可以看到,使用第二种[UIApplication sharedApplication] openURL这种方法调用的,并不会出现在app里面,这样无法获取到UIAlertController 无法去修改它的颜色。
控制台输出这是控制台输出,这个弹出框已经脱离了app本身。
这只是我的个人见解,如有解决方法,请私信我!谢谢
大家一起共同进步,共同成长。
网友评论