English 中文(简体)
如果有其他障碍,适用修改
原标题:Apply modifier on if else block

如下文守则所示,我在<条码>中应用了<>条码>;(<>>>>>条码/代码>,并在<条码>栏目和<条码>>栏目中应用了条码。

var body: some View {
    NavigationView {
        if model.mode == .active {
            activeList
                .frame(minWidth: 200)
        } else {
            trashedList
                .frame(minWidth: 200)
        }
    }
}

我如何消除<条码>框架(minWidth:)的重复?

更一般地说,如果在共同点有 mo者,结果又会如何?

问题回答

我可以建议你使用<代码>。 * E/CN.6/2009/1。

var body: some View {
    NavigationView {
        Group {
            if model.mode == .active {
                activeList
            } else {
                trashedList
            }
        }
        .frame(minWidth: 200)
    }
}

在这方面,你可以如何界定自己的变造。

struct MyDefaultWidthModifier: ViewModifier {    
    func body(content: Content) -> some View {
        return content
            .frame(minWidth: 200) // you can store this as a variable based on your needs
    }
}

合法使用:

NavigationView {
        if model.mode == .active {
            activeList
                .modifier(MyDefaultWidthModifier())
        } else {
            trashedList
                .modifier(MyDefaultWidthModifier())
        }
    }




相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

How to access own window within SwiftUI view?

The goal is to have easy access to hosting window at any level of SwiftUI view hierarchy. The purpose might be different - close the window, resign first responder, replace root view or ...

热门标签