swift - iOS Share to Mail 应用程序始终在顶部显示文本,在底部显示图像,而不是跟随数组中的内容
问题描述
我正在尝试将内容从我的应用程序共享到邮件。特别是我想拥有:
- 顶部的一些文字
- 图片在中间
- 底部的一些文字
然而,似乎我所有的文字都被推到了顶部,而图像在底部结束。我做错了什么,我该如何完成这个订单?
我目前正在分享
let content: [Any] = ["Top text", UIImage(systemName: "pencil")!, "Bottom Text"]
并得到以下结果,这不是我想要的。
这是我正在使用的代码。
import SwiftUI
enum Coordinator {
static func topViewController(_ viewController: UIViewController? = nil) -> UIViewController? {
let vc = viewController ?? UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.rootViewController
if let navigationController = vc as? UINavigationController {
return topViewController(navigationController.topViewController)
} else if let tabBarController = vc as? UITabBarController {
return tabBarController.presentedViewController != nil ? topViewController(tabBarController.presentedViewController) : topViewController(tabBarController.selectedViewController)
} else if let presentedViewController = vc?.presentedViewController {
return topViewController(presentedViewController)
}
return vc
}
}
struct ContentView: View {
func share() {
let content: [Any] = ["Top text", UIImage(systemName: "pencil")!, "Bottom Text"]
let activityViewController = UIActivityViewController(activityItems: content, applicationActivities: nil)
let viewController = Coordinator.topViewController()
activityViewController.popoverPresentationController?.sourceView = viewController?.view
activityViewController.completionWithItemsHandler = {(activityType: UIActivity.ActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in
}
viewController?.present(activityViewController, animated: true, completion: nil)
}
var body: some View {
Button(action: share) {
Text("Share")
}
.padding()
}
}
解决方案
推荐阅读
- javascript - 如何在 list.item 中获取按钮 onclick 的值
- java - 何时在 Java 中使用 Comparable[ ]?
- javascript - 如何更改 Stats.js 的大小?
- qt - 移动窗口无法正常工作
- react-native - Metro Bundler 在 react-native 目录中寻找 JS 文件
- reactjs - 预期一个赋值或函数调用,而是在使用 div 时在反应中看到一个表达式
- wordpress - Woocommece 类别和商店页面问题
- ios - 加载和刷新时间敏感数据的最佳实践
- jsrender - 如何在启用 AllowCode 的情况下使用上下文参数
- visual-studio-code - 创建项目时在VS Code中设置包