[swift] UIAlertControllerに画像を追加する
UIAlertControllerに画像を追加する
Alertを画面に表示させるUIAlertControllerは基本的に文字のみだが、画像をUIAlertController上に描画することができる
サンプルコード
let title = "GPS Course Creation"
let message = "Can create your course by GPS"
let alert = UIAlertController(title:title,
message: message,
preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction:UIAlertAction = UIAlertAction(title: "OK",
style: UIAlertActionStyle.Cancel,
handler:{
action in
})
alert.addAction(cancelAction)
let imageView = UIImageView(frame: CGRectMake(5, -40, 60, 60))
imageView.image = UIImage(named: "alert_gps.png")
alert.view.addSubview(imageView)
self.presentViewController(alert, animated: true, completion: nil)
結果:
