SwiftUI groups were introduced with iOS 13. They act as containers for wrapping different view types and also let you work around the 10 ChilidItem limit of VStack and HStack.

SwiftUI, in its second iteration at WWDC 2020, offers us a few new group controls. Namely, GroupBoxDisclosureGroup and OutlineGroup are now available in iOS 14 and above.

Let’s walk through each of these.


GroupBox

GroupBox is a stylized container view with an optional Label, and earlier it was only available in macOS. Now you can use it to logically group views and build things like a login screen, a custom alert dialog, and more.

Here’s the code that shows how to create a GroupBox in SwiftUI:

GroupBox(label: Label("Enter Details"), content: {

 VStack{
  TextField("Username", text: $text)
  Button(action: {}) {Text("Submit")}
 }
})

View modifiers work the same on GroupBox as they do on any other view. For instance, you can set shadows. The below screengrab shows a neumorphic design of the GroupBox in SwiftUI:

Image for post

Neumorphism is all about setting lights and shadows to give an extruding look, and that’s what’s done in the above code by using powerful view modifiers. The code is available in this gist.

#swift #ios #swiftui #programming #mobile

SwiftUI’s GroupBox, OutlineGroup, and DisclosureGroup in iOS 14
44.70 GEEK