【问题标题】:How can I place a circular progressView in a navigationBar with swiftui?如何使用 swiftui 在导航栏中放置圆形进度视图?
【发布时间】:2021-06-24 03:47:59
【问题描述】:

我有一个 swiftUI 项目,我想在导航栏中放置一个圆形进度视图,执行以下操作:

.toolbar {
    ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
        Button {
            // some action
        } label: {
            HStack {
                ProgressView()
                    .frame(width: 20, height: 20)
                    .progressViewStyle(CircularProgressViewStyle())
                Text("Save Edits")
            }
            
        }
    }
}

“保存编辑”出现,但progressView 没有。我猜 SwiftUI 只允许导航栏中的文本或图像作为工具栏项。想知道是否有任何其他方法可以在导航栏中获取循环进度视图。我在许多想要让用户在按下导航栏按钮时知道正在发生的事情的应用程序中看到了这一点。

【问题讨论】:

  • 似乎问题出在按钮中的 HStack 上。我需要做的是添加两个 ToolbarItems 并解决问题
  • 你可以看看这个教程youtube.com/watch?v=O3ltwjDJaMk

标签: ios xcode swiftui navigationbar


【解决方案1】:

问题似乎在于按钮中有一个 HStack。

这是其他人遇到此问题时的解决方案:

.toolbar {
    ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
        ProgressView()
            .progressViewStyle(CircularProgressViewStyle())
    }
    ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
        Button {
            // some action
        } label: {
            
            Text("Save Edits")
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-20
    • 2019-11-17
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多