1

我想在警报消息标题而不是标题文本中添加共享图像。 如何使用 swift 3 实现这一点?

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

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

1 回答 1

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)
于 2017-02-27T06:50:01.540 回答