ios - 在 UIAlertController 中将图像添加到 UIAlertAction

标签 ios uialertcontroller

我看过几个 UIAlertControllers 的屏幕截图,行的左侧有一个图像,但我没有在文档中看到它。视觉示例是 http://imgur.com/SISBvjB 这是我现在为我的 Controller 准备的代码:

UIAlertController * view =   [UIAlertController
                                 alertControllerWithTitle:@"My Title"
                                 message:@"Select you Choice"
                                 preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                          }];
    [view addAction:ok];
    [self presentViewController:view animated:YES completion:nil];

最佳答案

这就是它是如何完成的:

let image = UIImage(named: "myImage")
var action = UIAlertAction(title: "title", style: .default, handler: nil)
action.setValue(image, forKey: "image")
alert.addAction(action)

image 属性没有公开,所以不能保证这个在未来的版本中工作,但现在工作正常

关于ios - 在 UIAlertController 中将图像添加到 UIAlertAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26347085/

相关文章:

swift - 单击按钮时的 UIAlertController

swift - 为什么我的 UIPickerview 无法在 UIAlertcontroller 中工作?

swift - 我应该如何发出 swift 超时的警报

iOS AlertView 应用扩展

ios - UIActivityViewController 和 UIDocumentInteractionController 不显示选项

iphone - UIPrintInteractionController presentAnimated - 缓慢并挂起设备?

ios - Iphone 应用程序中的 Google 图像搜索集成

iOS ttf 字体只能部分工作

ios - 如何找到 map 中某个点的角度方向(相对于北方)

ios - 如何在 ObjC 中普遍更改 UIAlertController 按钮颜色