预览项目在黑暗模式下的效果是非常方便的。您将在本节课,在预览窗口观察文本、图标和图像在正常模式和黑暗模式下的效果。
示例代码:
struct ContentView : View { var body: some View { VStack(alignment: .center, spacing: 20){ Text("Dynamic Type sizes") .font(.system(size: 48)) .foregroundColor(Color.secondary) Text("Dynamic Type sizes") .foregroundColor(Color.accentColor) Image(systemName: "star.fill") .foregroundColor(Color.secondary) .font(.system(size: 64)) } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .background(Color.primary) .edgesIgnoringSafeArea(.all) } } #if DEBUG struct ContentView_Previews : PreviewProvider { static var previews: some View { HStack { ContentView() .environment(\.colorScheme, .light) ContentView() .environment(\.colorScheme, .dark) } } } #endif