0

Xcode Version - 13.1

I'm having some issues with a Background Img & the grouping Form{}. What's happening is when placing a background image in a ZStack and include the grouping option, Form{}, the Background Img disappears.

Below my code showing my Background Image inside a ZStack. Also including a link to a screen shot of the Preview -> https://i.stack.imgur.com/u12Sw.png

    var body: some View {

        ZStack {
            Image("login")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)
        }
    }

However, when I add a Form{} inside the ZStack, the background image completely disappears and only the Form{} (w/ a TextField &SecureTextField) appears on the Preview Sans the Background Img. Below is the code w/ and a link to the Screen shot of the Preview -> https://i.stack.imgur.com/BI3U2.png

var body: some View {

        ZStack {
            Image("login")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)

            Form {
                    TextField(
                        "Username (email)",
                        text: self.$username)
                        .autocapitalization(.none)
                        .disableAutocorrection(true)
                    SecureTextField(text: $password)
                }
            }
        }

My assumption is that as long as the Form is inside the ZStack, the form should overlay the Background Img.

I like how the Form looks rather than two separate TextFields. Are there anyways to do this w/ the Form or something similar to a Form?

  • It is not disappeared, Forms is just not transparent and covers all screen - image remains behind it. – Asperi Dec 12 '21 at 16:09
  • @Asperi Thanks for the info. Maybe I'll adjust my question to ask for ways around this? I like how the Form looks rather than 2 separate TextFields. – William Zebrowski Dec 12 '21 at 16:20
  • [Does this](https://stackoverflow.com/questions/63945992/clear-background-for-form-sections-in-swiftui) answer your question? – Yrb Dec 12 '21 at 17:16

1 Answers1

1

This is what I do at the moment: I either add this modifier to the form.

.onAppear {
            UITableView.appearance().backgroundColor = .clear
        }

Or in an init() of the View

this has some side effects on the rest of the view if you have List or Forms but it works for me.