Search code examples
swiftxcodeuitableviewswiftuiswiftui-form

SwiftUI Form style changed when embedded in UIHostingViewController


I have A SwiftUI view which is a standard form and in canvas it has the built in IOS form style which is the look I desire.

However this form is being used a SideBar embedded in a UIHostingViewController which is a child of a UIViewController. Everything works as expected however the styling of the form is replaced by that of a normal UITableViewController.

I have not added any code because my struct is a simple form with multiple sections.

Please refer to the images below

Expected Look as it shows in canvas enter image description here

Actual look after being embedded in UIHostingViewController SideBar


Solution

  • I was able to fix this issue by simply changing the widthAnchor of the form and allowing it more size.

    I noticed that when I rotated my device and the UIHostingViewControllers frame changed its widthAnchor and the SwiftUI view rendered correctly on screen.