【问题标题】:How to unmute colors in SwiftUI's NavigationSplitView sidebar如何取消 SwiftUI 的 NavigationSplitView 侧边栏中的颜色静音
【发布时间】:2023-01-15 07:58:51
【问题描述】:

我正在使用在 iOS16 中引入的NavigationSplitView,带有一个基本列表,并尝试使用标准颜色为系统图像着色。我注意到当 navigationSplitViewStyle.automatic.prominentDetail 并且配色方案是深色时,颜色被静音。我一直无法弄清楚如何不使它们静音,从而坚持在灯光模式下使用的原始颜色。我想知道这是否可以覆盖?或者有没有办法下降到 UIKit 并覆盖这种奇怪的行为?

这是一个例子:

import SwiftUI

struct ContentView: View {
  var body: some View {
    NavigationSplitView {
      List {
        ForEach([1, 2, 3], id: \.self) { item in
          Button {
          } label: {
            HStack {
              Image(systemName: "sunset.circle.fill")
                .foregroundColor(.green)
              Text("Item \(item)")
            }
            .font(.system(size: 40))
            .padding()
          }
        }
      }
    } detail: {
      Text("Detailed Content")
    }
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    Group {
      ContentView()
        .previewInterfaceOrientation(.portrait)
        .preferredColorScheme(.dark)
      ContentView()
        .previewInterfaceOrientation(.portrait)
        .preferredColorScheme(.light)
    }
  }
}

您可以在此处看到方案之间颜色的不同:

【问题讨论】:

    标签: arrays swift swiftui-navigationsplitview navigationsplitview


    【解决方案1】:

    如果你的意思是在黑暗模式下,符号中的太阳是黑色的,你想保持它是白色的,那么你可以通过将图像上的 symbolRenderingMode 修饰符设置为 .palette 并给它两种颜色,绿色的一种来实现以及使用 foregroundStyle 修饰符的白色。

    Image(systemName: "sunset.circle.fill")
        .symbolRenderingMode(.palette)
        .foregroundStyle(.white, .blue)
    

    如果这回答了您的问题,请不要忘记将其标记为已接受的答案。 编码愉快!

    【讨论】:

      猜你喜欢
      • 2022-08-22
      • 2020-01-10
      • 2021-03-11
      • 2014-10-04
      • 1970-01-01
      • 2020-10-26
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多