【问题标题】:Add Image in Alert Message box Title with Swift 3使用 Swift 3 在警报消息框标题中添加图像
【发布时间】:2017-02-27 05:27:40
【问题描述】:

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

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

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

【问题讨论】:

  • 你的问题得到答案了吗?
  • 我还没有尝试过兄弟@HardikShekhat。我会尽快尝试。这几天我身体不太好。这就是为什么。谢谢你问我。 :) 我会回复结果。
  • 你好兄弟@HardikShekhat,我现在试试你的代码。图像出现在警报框中,但我想在警报框标题中显示它。目前,我删除标题文本。那么,兄弟,我怎样才能把这张图片放在标题位置呢?
  • 兄弟@HardikShekhat,现在可以了。 let alertController = UIAlertController(title:"", message:"\n I would like to share.", preferredStyle: .alert) 然后我调整 x, y 值。现在好了,兄弟。非常感谢。 :)
  • 我在写答案之前尝试了下面的代码。它出现在标题位置的图像。也许你写错了什么?所以,请再检查一遍。

标签: swift uialertview uialertcontroller uialertaction


【解决方案1】:

试试这个。或许能帮到你。

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)

【讨论】:

猜你喜欢
  • 2016-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多