最近想要在項目更好的優化下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 了就是上面的代碼。 這種方式調用出來的是可以看到的 也是嵌入在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
從這個圖層上可以看到,使用第二種[UIApplication sharedApplication] openURL這種方法調用的,并不會出現在app里面,這樣無法獲取到UIAlertController 無法去修改它的顏色。
這是控制臺輸出,這個彈出框已經脫離了app本身。
這只是我的個人見解,如有解決方法,請私信我!謝謝
大家一起共同進步,共同成長。