struct ContentView: View { @State private var toggleLayout = false var body: some View { let layout = toggleLayout ? AnyLayout(HStack()) : AnyLayout(VStack()) layout { Text("DevTechie.com") .font(.largeTitle) .foregroundColor(.primary) Image(systemName: "swift") .font(.largeTitle) } .padding() .onTapGesture { toggleLayout.toggle() } } }
struct ContentView: View { @State private var toggleLayout = false var body: some View { let layout = toggleLayout ? AnyLayout(HStack()) : AnyLayout(VStack()) layout { Text("DevTechie.com") .font(.largeTitle) .foregroundColor(.primary) Image(systemName: "swift") .font(.largeTitle) } .padding() .onTapGesture { withAnimation { toggleLayout.toggle() } } } }
struct ContentView: View { @State private var toggleLayout = false @State private var themeColor = Color.blue var body: some View { let layout = toggleLayout ? AnyLayout(HStack()) : AnyLayout(VStack()) VStack { layout { Text("DevTechie.com") .font(.largeTitle) Image(systemName: "swift") .font(.largeTitle) } .foregroundColor(themeColor) .padding() .onTapGesture { withAnimation { toggleLayout.toggle() } } Button("Change color") { themeColor = themeColor == .blue ? .orange : .blue } } } }
struct ContentView: View { @Environment(\.verticalSizeClass) var vSizeClass @State private var themeColor = Color.blue var body: some View { let layout = vSizeClass == .compact ? AnyLayout(HStack()) : AnyLayout(VStack()) VStack { layout { Text("DevTechie.com") .font(.largeTitle) Image(systemName: "swift") .font(.largeTitle) } .foregroundColor(themeColor) .padding() Button("Change color") { themeColor = themeColor == .blue ? .orange : .blue } } } }
With that we have reached the end of this article. Thank you once again for reading. Subscribe our newsletter at https://www.devtechie.com