本节课演示如何在预览窗口,使用不同的模拟器预览用户界面。
示例代码:
struct ContentView : View { var body: some View { VStack{ Text("Dynamic Type sizes") .font(.system(size: 48)) Text("Dynamic Type sizes") } } } #if DEBUG struct ContentView_Previews : PreviewProvider { static var previews: some View { Group { ContentView() .previewDevice(PreviewDevice(rawValue: "iPhone 8")) .previewDisplayName("Device-8") ContentView() .previewDevice(PreviewDevice(rawValue: "iPhone XS Max")) .previewDisplayName("Device-XS Max") } } } #endif