【问题标题】:In SwiftUI how can I bold the primaryAction ToolbarItem?在 SwiftUI 中,如何将primaryAction ToolbarItem 加粗?
【发布时间】:2021-02-18 03:56:54
【问题描述】:

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

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

primaryAction 位置未加粗:

主要位置默认为粗体:

【问题讨论】:

    标签: swiftui swiftui-navigationview


    【解决方案1】:

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

    .toolbar {
      ToolbarItem(placement: ToolbarItemPlacement.confirmationAction) {
        Button {
          //do something
        } label: {
          Text("Save")
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多