这是我的警报,效果很好。我想向警报添加一个图像,该图像在出现警报时显示在文本旁边,如果它有所不同,我在 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/