html - Swift:带有 HTML 内容的 UIActivityViewController

标签 html ios swift uiactivityviewcontroller

如何发送带有 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/

相关文章:

html - 为特定文件中的元素启用 CSS

objective-c - 在 Block 中释放 View Controller 的位置

ios - 无法使用 Firebase 身份验证 : FIRAuth. 身份验证不起作用

swift - 使用自动布局约束旋转后对齐 UILabel 文本

SwiftUI 分段选取器在单击时不会切换

html - 由 CSS 剪辑引起的闪烁微调器?

javascript - 防止在隐藏和显示时推送元素 - jQuery

html - 现在 HTML5 有一个用于呈现页面的标准算法,它是否仍然对验证标记有用?

ios - Objective-C:如何制作自定义水平 ScrollView

ios - 使用 swift 将当前用户的消息列表保存在解析中