Hi! In SwiftUI, what is the difference between Form and other containers, such as VStack?
I saw some examples of using Form to allow users to input data, but still wasn't able to tell what will be the difference if I use VStack instead.
Can you tell me the difference?
Thank you!
I saw some examples of using Form to allow users to input data, but still wasn't able to tell what will be the difference if I use VStack instead.
Can you tell me the difference?
Thank you!
You can try it for yourself.
Run these two bits of code and you will see the difference:
A Form places the views in a List with an InsetGroupedListStyle (iOS).
It is just a container that is platform-adaptive that shows a form.
A VStack just places the views vertically: above and below each other.
Check the documentation for Form and VStack for more detail.
Run these two bits of code and you will see the difference:
Code Block Swift Form { Text("I’m in a Form") Button("Tap Me!") { print("Button tapped") } }
Code Block Swift VStack { Text("I’m in a VStack") Button("Tap Me!") { print("Button tapped") } }
A Form places the views in a List with an InsetGroupedListStyle (iOS).
It is just a container that is platform-adaptive that shows a form.
A VStack just places the views vertically: above and below each other.
Check the documentation for Form and VStack for more detail.