将图像添加到UIAlertController

编程入门 行业动态 更新时间:2024-10-11 07:27:45
本文介绍了将图像添加到UIAlertController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将图像添加到UIAlertController.图像不必位于按钮上,只需显示在控制器的中间即可.我的代码在下面,但是由于消息无法识别的选择器发送到实例"而崩溃.

I want to add an image to UIAlertController. Image does not need to be on a button, just presented in the middle of the controller. The code I have is below but crashes with message "unrecognised selector sent to instance".

func showAlert () { let alert = UIAlertController(title: "Title of Alert", message: "none", preferredStyle:UIAlertControllerStyle.ActionSheet) // add an image let image = UIImage(named: "example") var imageView = UIImageView(image: image) imageView.frame = CGRectMake(0, 0, 100, 100) var imageAction = UIAlertAction(title: "", style:.Default, handler: nil) imageAction.setValue(imageView, forKey: "image") alert.addAction(imageAction) // add a continue button var action = UIAlertAction(title: "Continue", style:.Default, handler: {(alert:UIAlertAction!) in self.continue() }) alert.addAction(action) // show the UIAlertController self.presentViewController(alert, animated: true, completion: nil) }

推荐答案

不幸的是,Apple不允许我们将图像添加到UIAlertController或UIAlertView.这些API仅限于Apple的人机界面指南.

Unfortunately Apple does not allow us to add images to UIAlertController or UIAlertView. These APIs are limited to Apple's Human Interface Guidelines.

如果您确实需要类似UIAlertController的对话框中的图像,我建议您尝试使用类似 github/wimagguc/ios-custom-alertview .

If you really need an image in a UIAlertController-like dialog, I would recommend trying to use something like github/wimagguc/ios-custom-alertview.

更多推荐

将图像添加到UIAlertController

本文发布于:2023-08-06 11:29:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1311982.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   UIAlertController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!