【问题标题】:How to add if else statement on padding? SwiftUI如何在填充上添加 if else 语句? SwiftUI
【发布时间】:2022-07-27 02:40:44
【问题描述】:

我想仅在 showBar = false 时将填充设置为 -15,如何在内部填充参数中添加条件? 这适用于 macOS 10.15 应用程序。

@State private var showBar = true

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

【问题讨论】:

    标签: swift swiftui


    【解决方案1】:

    在修饰符内使用三元运算符,如

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-19
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 2018-10-29
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多