import SwiftUI
struct ContentView: View {
@State var counter: Counter = Counter()
var body: some View {
VStack(spacing: 10) {
Text("\(counter.count)")
Button("Button +") {
counter.increase()
}
Button("Button -") {
counter.decrease()
}
}
.padding()
}
}
//#Preview {
// ContentView()
// .previewLayout(PreviewLayout.sizeThatFits)
// .padding()
// .previewDisplayName("Default preview 1")
//}
struct ContentView_Preview: PreviewProvider {
static var previews: some View{
ContentView()
.previewLayout(PreviewLayout.sizeThatFits)
.padding()
.previewDisplayName("Default preview 1")
}
}
如图所示,文件默认的代码是
#Preview {
ContentView()
}
上面注释掉的写法previewLayout
/previewDisplayName
都不生效