UIAlertController customization

天涯浪子 提交于 2019-12-02 17:36:52

问题


I'm trying to customize my UIAlertController with a dark theme.
I'm aiming for something like this

I'm trying different things, including the suggestion I found here https://stackoverflow.com/a/29122883/1817873, but for some reason only the first button gets colored while the cancel button keeps staying white.

Here is my code:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:deleteAction];
[alert addAction:cancelAction];

UIView *firstView = alert.view.subviews.firstObject;
UIView *nextView = firstView.subviews.firstObject;
nextView.backgroundColor = [UIColor blackColor];

Any ideas?


回答1:


Any ideas?

Yes. Give up. An alert controller is very limited, and you should stick to what it does. But it is just a presented view controller, and nothing stops you from making your own presented view controller that looks and acts just like an alert, and since it is your view controller, it's your view and you can do whatever you like.




回答2:


If you're still struggling with this, I have a library that may be of help. It lets you create custom action sheets. It has a bunch of built-in types and can be extended and restyled as well.



来源:https://stackoverflow.com/questions/36022914/uialertcontroller-customization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!