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

标签 swift uialertview uialertcontroller uialertaction

我想在警告消息 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))

最佳答案

试试这个。也许对你有帮助。

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)

关于swift - 使用 Swift 3 在警告消息框标题中添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42478380/

相关文章:

objective-c - 多任务手势不适用于警报

swift - CollectionViewCell、MapView 和自定义注释

ios - 如何在 UIAlertView 中添加 UIWebview?

swift - 如何在 macOS 上以编程方式在 Swift 中添加 NSView

ios - AlertView 委托(delegate)方法alertViewShouldEnableFirstOtherButton 未调用Swift

ios - 居中对齐 UIAlertController 中的图像操作

ios - 从 UIAlertAction 处理程序更新 UILabel 在 Swift 4 中不起作用

iOS 媒体库 : React to Access Apple Music Alert

javascript - WKScriptMessageHandler 不会在网页上的按钮元素上监听 'onclick' 或 'click' 事件。网页使用Reactjs开发

ios - Swift:在标签周围画一个圆圈