UIAlertController自定义 [英] UIAlertController customization

查看:46
本文介绍了UIAlertController自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用深色主题自定义我的UIAlertController.
我的目标是这样的

我正在尝试不同的方法,包括我在这里找到的建议 https://stackoverflow.com/a/29122883/1817873 ,但是由于某些原因,只有第一个按钮会变色,而取消按钮会保持白色.

这是我的代码:

  UIAlertController * alert = [UIAlertController alertControllerWithTitle:n消息:nil preferredStyle:UIAlertControllerStyleActionSheet];UIAlertAction * deleteAction = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:nil];UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel"样式:UIAlertActionStyleCancel处理程序:无];[alert addAction:deleteAction];[alert addAction:cancelAction];UIView * firstView = alert.view.subviews.firstObject;UIView * nextView = firstView.subviews.firstObject;nextView.backgroundColor = [UIColor blackColor]; 

有什么想法吗?

解决方案

有什么想法吗?

是的.放弃.警报控制器非常有限,您应该坚持执行它.但这只是一个呈现的视图控制器,并没有阻止您制作外观和行为类似于警报的呈现的视图控制器的功能,并且由于它是您的视图控制器,因此您的视图就是您可以做的任何事情.

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?

解决方案

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.

这篇关于UIAlertController自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆