在 ToolbarItem SwiftUI 中添加带有图像和文本的按钮

Jig*_*gar 6 ios swift swiftui

我想要按钮与 iOS 中的“提醒”应用程序完全相同,下面的代码注释可以正常工作,我还尝试使用标签和系统图像名称。

        .toolbar {
            ToolbarItem(placement: .bottomBar) {
                Button(action: {}, label: {
                    HStack {
                        Image(systemName: "plus.circle.fill")
                        Text("New Reminder")
                    }
                })

            }
        }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

小智 1

创建自定义标签样式

struct VerticalLabelStyle: LabelStyle {
    func makeBody(configuration: Configuration) -> some View {
        VStack {
            configuration.icon.font(.headline)
            configuration.title.font(.footnote)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后您可以为标签使用自定义样式

Button(action: {}, label: {
   Label("Home", systemImage: "house")
      .labelStyle(VerticalLabelStyle())
})
Run Code Online (Sandbox Code Playgroud)

下面有标题的图标