How to put background image on SwiftUI Form

Viewed 550

I have the below following code and I want to put some image to the area that highlighted in red. How can I do that in SwiftUI?

Here is highlighted red area example: https://ibb.co/6X2zvyq

struct ContentView: View {
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("Info")) {
                    HStack {
                        Text("Name")
                        Spacer()
                        Text("someName")
                    }
                    HStack {
                        Text("Surname")
                        Spacer()
                        Text("someSurname")
                    }
                }
            }
            .navigationBarTitle("Profile")
        }
    }
}
1 Answers

Here is complete one module code. Tested with Xcode 11.7. Image named "plant" is located inside Assets.xcassets

demo

extension UINavigationController {
    override open func viewDidLoad() {
        super.viewDidLoad()

        let appearance = UINavigationBarAppearance()
        appearance.configureWithTransparentBackground()
        appearance.backgroundImage = UIImage(named: "plant")

        navigationBar.standardAppearance = appearance
        navigationBar.compactAppearance = appearance
        navigationBar.scrollEdgeAppearance = appearance
    }
}

struct ContentView: View {
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("Info")) {
                    HStack {
                        Text("Name")
                        Spacer()
                        Text("someName")
                    }
                    HStack {
                        Text("Surname")
                        Spacer()
                        Text("someSurname")
                    }
                }
            }
            .navigationBarTitle("Profile")
        }
    }
}
Related