How it works
FormStyleConfiguration carries the properties of a form to a custom form style, giving you the form's resolved content so you can lay it out however you like. When you adopt the FormStyle protocol, SwiftUI hands you a value of this type inside makeBody(configuration:); it is the bridge between the rows a developer writes in a Form and the chrome your style draws around them. Reach for it whenever the built-in form styles don't match your design and you need full control over how a form's content is arranged.
Receive it through FormStyle.makeBody(configuration:)
A custom form style conforms to FormStyle and implements makeBody(configuration:), whose parameter type is the protocol's Configuration associated type — an alias for FormStyleConfiguration. You never construct the value yourself; SwiftUI creates it and passes it in each time a form using your style needs to render. In the example, CardFormStyle declares func makeBody(configuration: Configuration) -> some View to receive it.
Read the form's rows from configuration.content
The content property is the configuration's single payload: an opaque view holding everything the developer placed inside the Form. Place it wherever you want the rows to appear in your layout, and the form's fields render at that spot. The example drops configuration.content into a VStack beneath a header, so the TextField and Toggle flow directly under the title.
Wrap the content in your own container
Because content is just a view, you compose your style's appearance around it with ordinary SwiftUI containers and modifiers. Here the rows are nested in a VStack(alignment: .leading, spacing: 12) alongside a Text("Settings") header, then given .padding(), a .background(.gray.opacity(0.15)), and .cornerRadius(12) to produce the card treatment.
Attach the style with formStyle(_:)
A style only takes effect once it is applied to a Form via the formStyle(_:) modifier, which is where SwiftUI begins routing the form's content through your makeBody implementation and the FormStyleConfiguration it provides. In the example, .formStyle(CardFormStyle()) on the Form is what activates the custom layout.
Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct FormStyleConfigurationDemo: View {
var body: some View {
Form {
TextField("Name", text: .constant("Ada"))
Toggle("Notifications", isOn: .constant(true))
}
.formStyle(CardFormStyle())
.padding()
}
}
struct CardFormStyle: FormStyle {
func makeBody(configuration: Configuration) -> some View {
VStack(alignment: .leading, spacing: 12) {
Text("Settings")
.font(.headline)
configuration.content
}
.padding()
.background(.gray.opacity(0.15))
.cornerRadius(12)
}
}