使用Swift 3在警报消息框标题中添加图像

时间:2017-02-27 05:27:41

标签: swift uialertview uialertcontroller uialertaction

我想在提醒消息标题中添加分享图片,而不是标题文字。
如何用swift 3实现这个?

let alertController = UIAlertController(title: "Share Movie", message: "Share this movie!", preferredStyle: .alert)

    alertController.addAction(UIAlertAction(title: "Share", style: UIAlertActionStyle.default, handler: nil))

1 个答案:

答案 0 :(得分:7)

试试这个。也许帮助你。

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)

let action = UIAlertAction(title: "OK", style: .default, handler: nil)

let imgTitle = UIImage(named:"imgTitle.png")
let imgViewTitle = UIImageView(frame: CGRect(x: 10, y: 10, width: 30, height: 30))
imgViewTitle.image = imgTitle

alert.view.addSubview(imgViewTitle)
alert.addAction(action)

self.present(alert, animated: true, completion: nil)