在UIAlertController中将图像添加到UIAlertAction [英] Add Image to UIAlertAction in UIAlertController

查看:177
本文介绍了在UIAlertController中将图像添加到UIAlertAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过UIAlertControllers的几个屏幕截图,行左边有一个图像,但我没有在文档中看到它。视觉示例是
以下是我现在为我的控制器提供的代码:

I have seen a couple screen shots of a UIAlertControllers with an image on the left of the row but I do not seen it in the documentation. An example visual is Here is the code that I have for my controller right now:

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)

图片属性未公开,因此无法保证在将来的版本中有效,但现在工作正常

the image property is not exposed, so there's no guarantee of this working in future releases, but works fine as of now

这篇关于在UIAlertController中将图像添加到UIAlertAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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