ios - 将图像添加到 UIAlertController

标签 ios swift uialertcontroller

这是我的警报,效果很好。我想向警报添加一个图像,该图像在出现警报时显示在文本旁边,如果它有所不同,我在 SpriteKit 中的 SKScene 中。

var alertController = UIAlertController(title: "How to Skate", message: "Tap the screen to perform a trick and jump over the obsticles (You can grind on rails) The game will end when you hit a highlighted red, orange or yellow obstacle. That's it! + Image", preferredStyle: UIAlertControllerStyle.Alert)     
alertController.addAction(UIAlertAction(title: "Cool!", style: UIAlertActionStyle.Cancel, handler: nil))
self.view?.window?.rootViewController?.presentViewController(alertController, animated: true, completion: nil)

最佳答案

您可以将 UIImageView 作为 subview 添加到您的 UIAlertController

var imageView = UIImageView(frame: CGRectMake(220, 10, 40, 40))
imageView.image = yourImage
alert.view.addSubview(imageView)

这就是你在 UIAlertController 中的做法:

let alertMessage = UIAlertController(title: "My Title", message: "My Message", preferredStyle: .Alert)

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

self.presentViewController(alertMessage, animated: true, completion: nil)

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

相关文章:

ios - 在 UIcollectionview 中出列多个单元格的方法

ios - 我如何检查另一个 View Controller 是否可见?

ios - 从 swift 2.2 中的 plist 的字典和数组的组合中获取数据

iOS 8 testflight beta 推送通知 token

ios - 在点击它之后但在使用 IOS 操作之前更改 UIview 颜色

ios - UIAlertView/UIAlertController iOS 7 和 iOS 8 兼容性

ios - UIActionSheet/UIAlertController 多行文本

ios - 如何使用 Swift 创建 UISearchBar 以搜索我的 Tableview 数据的选项?

ios - 如何在 Swift 中向泛型类型添加类型方法?

ios - 自定义控件的 Storyboard 中出现奇怪的错误