如何自定义SwiftUI文件导出器以显示”保存”而不是”移动”

huangapple go评论77阅读模式
英文:

How to customize swiftui file exporter to show save instead of move

问题

我想允许用户导出一个文本文件并将其保存到他们的文件系统中。然而,SwiftUI 在弹出视图中显示一个按钮,上面写着“移动”,而不是“保存”。我该如何更改这种行为?
英文:

I would like to allow user to export a text file and save it to their filesystem. However, swiftUI shows a button that says move in the popupview instead of save. how can I change that behavior.

如何自定义SwiftUI文件导出器以显示”保存”而不是”移动”

struct FileExporterDemo: View {
    @State private var showingExporter = false

    var body: some View {
        Button("export"){showingExporter = true}
        .fileExporter(isPresented: $showingExporter, document: TextFile(initialText: "test"), contentType: .plainText) { result in
            switch result {
            case .success(let url):
                print("Saved to \(url)")
            case .failure(let error):
                print(error.localizedDescription)
            }
        }    }
}

答案1

得分: 1

iOS 不允许我们更改 FileExporter 的导航栏项目标题,因为它使用了官方文档中提到的系统偏好设置。

func fileExporter<C>(isPresented: Binding<Bool>, documents: C, contentType: UTType, onCompletion: (Result<[URL], Error>) -> Void) -> some View

提供了一个用于允许用户将一组内存中的文档导出到磁盘文件的系统界面

英文:

iOS doesn't allow us to change title of navigationBar items for FileExporter because it is using System preferences as mentioned in offical document.

func fileExporter<C>(isPresented: Binding<Bool>, documents: C, contentType: UTType, onCompletion: (Result<[URL], Error>) -> Void) -> some View

Presents a system interface for allowing the user to export a collection of in-memory documents to files on disk.

huangapple
  • 本文由 发表于 2023年1月9日 01:04:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定