Home > Mobile >  How to add if else statement on padding? SwiftUI
How to add if else statement on padding? SwiftUI

Time:07-27

I want to set the padding to -15 only when showBar = false, how do i add the condition for this inside padding parameters? This is for macOS 10.15 app.

@State private var showBar = true

          VStack {
          WebView          
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .edgesIgnoringSafeArea(.all)
            .padding(.top, -15)

CodePudding user response:

Use ternary operator right inside modifier, like

.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
.padding(.top, showBar ? 0 : -15)  // << here !!
  • Related