ios – 将图像添加到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作为子视图添加到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,completion: nil)

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...