我甚至不确定这是否可行,但无论如何它仍然存在:
我的应用程序中有RTF文件,用于填充文本视图。我希望我的用户能够在这些文件中共享文本,而不是文件本身。
这是我目前用来共享文件的代码:
@IBAction func shareRecipeTxtBtn(_ sender: Any) {
let grabIngredientTxt = Bundle.main.url(forResource: "bananaPancakes_ing", withExtension: "rtf")
let grabDirectionTxt = Bundle.main.url(forResource: "bananaPancakes_dir", withExtension: "rtf")
let txtToShare = [grabIngredientTxt, grabDirectionTxt]
let activityViewController = UIActivityViewController(activityItems: txtToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.excludedActivityTypes = [UIActivityType.postToFacebook, UIActivityType.postToTwitter]
self.present(activityViewController, animated: true, completion: nil)
}
附带的屏幕截图是上述代码的结果,但它并不理想。
答案 0 :(得分:0)
为什么不抓住文本视图中显示的文本
let txtToShare = [textView1.text, textView2.text]
或
let txtToShare = ["\(textView1.text)\n\(textView2.text)]