在 SwiftUI 中,如何加粗 PrimaryAction ToolbarItem?

And*_*art 3 swiftui swiftui-navigationview

如何让 ToolbarItem 将primaryAction 加粗?我已经能够通过在导航视图上设置强调色来更改颜色。主要寻找 SwiftUI 解决方案,但如果不可能,我会选择 UI Kit 解决方案。我的代码:

.toolbar {
  ToolbarItem(placement: ToolbarItemPlacement.primaryAction) {
    Button(action: { }) {
      Text("Save")
        .fontWeight(.black) // does nothing
        .bold() // does nothing
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

PrimaryAction 位置未加粗:

PrimaryAction 位置未加粗

默认情况下,主要配置以粗体显示:

默认情况下,本金配售以粗体显示

小智 10

我也为此挣扎了一段时间。解决方案是使用.confirmationAction代替.primaryAction. 这会在相同的位置呈现,但使用粗体文本,至少目前如此(在 iOS 14 上)。

.toolbar {
  ToolbarItem(placement: ToolbarItemPlacement.confirmationAction) {
    Button {
      //do something
    } label: {
      Text("Save")
    }
  }
}
Run Code Online (Sandbox Code Playgroud)