演示-在SwiftUI的顶部显示一个视图(我不想导航)

问题描述 投票:0回答:1

嘿,我想在View的中间显示一个自定义View,我试图添加ZStack并居中,但是不起作用..这是我的代码

 var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            headerView.padding().background(Color.white)
            ZStack(alignment: .center) {
                if(incomeFill_show) {
                    BudgetAlert(amount: .constant("400"))
                }

                List() {
                    VStack {
                        Section(header: self.getHeaderView()) {
                            ForEach(categoriesData) { category in
                                HStack(alignment: .bottom) {
                                    CategoryProgressView(category: category, value: .constant(.random(in: 0.1 ... 1)))
                                    self.valuesText(category: category)
                                }

                            }
                            .colorMultiply(Colors.SharedColors.backgroundColor)
                        }
                    }
                }
                .colorMultiply(Colors.SharedColors.backgroundColor)
                .onAppear {UITableView.appearance().separatorStyle = .none}
                .onDisappear { UITableView.appearance().separatorStyle = .singleLine }
            }


        }.background(Colors.SharedColors.backgroundColor)
    }

我只想显示BudgetAlert(),背景像这样模糊:

enter image description here

swift swiftui
1个回答
0
投票

我通过放置解决了

if(incomeFill_show) {
                    BudgetAlert(amount: .constant("400"))
                }

在列表的底部:像这样

var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            headerView.padding().background(Color.white)
            ZStack(alignment: .center) {

                List() {
                    VStack {
                        Section(header: self.getHeaderView()) {
                            ForEach(categoriesData) { category in
                                HStack(alignment: .bottom) {
                                    CategoryProgressView(category: category, value: .constant(.random(in: 0.1 ... 1)))
                                    self.valuesText(category: category)
                                }

                            }
                            .colorMultiply(Colors.SharedColors.backgroundColor)
                        }
                    }
                }
                .colorMultiply(Colors.SharedColors.backgroundColor)
                .onAppear {UITableView.appearance().separatorStyle = .none}
                .onDisappear { UITableView.appearance().separatorStyle = .singleLine }

                if(incomeFill_show) {
                    BudgetAlert(amount: .constant("400"))
                }
            }


        }.background(Colors.SharedColors.backgroundColor)
    }
}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.