如何发送带有 HTML 文本的电子邮件?我使用此代码从我的 swift 应用程序发送电子邮件:
let subject = "Email test"
let content = "This is some text that I want to share."
// set up activity view controller
let objectsToShare = [content]
let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityViewController.setValue(subject, forKey: "Subject")
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
我希望内容有一些 HTML 标签并被解释为 HTML。
我该怎么做?谁能给我一个例子吗?
最佳答案
我不知道你是否还在寻找答案,但如果你是,你只需要将 html 标签放在你的内容周围:
let content = "<html><body>This is some text that I want to share.</body></html>"
您还可以创建 UIActivityItemProvider 的子类,以便根据应用程序将 html 转换为 NSAttributedString(例如,邮件应用程序支持 html,但对于笔记应用程序,您可以将其转换为 NSAttributedString)。
关于html - Swift:带有 HTML 内容的 UIActivityViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40578934/