简体   繁体   English

RoundedRectangle 背景留下一个未着色的间隙

[英]RoundedRectangle background leaves an uncolored gap

I wanted to make a RoundedRectangle that shows all the information and under it, there's a list of data.我想做一个显示所有信息的 RoundedRectangle,在它下面有一个数据列表。 The goal was, to make it look like a card, but when I change the background, it leaves a weird white gap, where it doesn't change the color.目标是让它看起来像一张卡片,但是当我改变背景时,它会留下一个奇怪的白色间隙,它不会改变颜色。 I already tried to change the background color, foreground color, accent color and everything I know for every single layer but I can't find the problem...我已经尝试为每一层更改背景颜色、前景色、强调色以及我所知道的所有内容,但我找不到问题...

I made the RoundedRectangle.background green in this case, to make it more obvious.在这种情况下,我将 RoundedRectangle.background 设为绿色,以使其更加明显。

Picture of the app, arrows are edited!应用程序的图片,箭头已编辑!

```var body: some View {
    NavigationView {
        VStack(alignment: .center) {
            ZStack {
                RoundedRectangle(cornerRadius: 25)
                .padding()
                .foregroundColor(.white)
                .background(Color.green)
                .frame(width: nil, height: 250)
                VStack {
                    Text("Verfügbar")
                        .foregroundColor(.gray)
                        .italic()
                        .font(.title2)
                    Text("\(totalMoneyToday(), specifier: "%.2f")€")
                        .foregroundColor(.blue)
                        .bold()
                        .font(.largeTitle)
                    HStack {
                        Spacer()
                        VStack(alignment: .leading) {
                            Text("Einkommen")
                                .foregroundColor(.gray)
                                .italic()
                            HStack {
                        Label("", systemImage: "arrow.up.circle")
                            .foregroundColor(.green)
                                Text("\(posMoney(), specifier: "%.2f")€").bold()
                            }
                        }
                        Spacer()
                        VStack(alignment: .trailing) {
                            Text("Ausgaben")
                                .foregroundColor(.gray)
                                .italic()
                            HStack {
                        Label("", systemImage: "arrow.down.circle")
                            .foregroundColor(.red)
                                Text("\(negMoney(), specifier: "%.2f")€").bold()
                            }
                        }
                        Spacer()
                    }
                    .padding(5)
                }
            }.background(Color.red)
            List {
                ForEach(money) { money in
                    NavigationLink(destination: EditMoneyView(money: money)) {
                        HStack {
                            VStack(alignment: .leading, spacing: 6) {
                                Text(money.name!)
                                    .bold()
                                
                                Text("\(money.amount, specifier: "%.2f")") + Text("€")
                            }
                            Spacer()
                            Text("\(money.date!, style: .date)")
                                .foregroundColor(.gray)
                                .italic()
                        }
                    }
                }
                .onDelete(perform: deleteMoney)
            }
        }
        .navigationBarTitle("Financist", displayMode: .inline)
        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                Button {
                    showingAddView.toggle()
                } label: {
                    Label("Hinzufügen", systemImage: "plus.circle")
                }
            }
        }
        .sheet(isPresented: $showingAddView) {
            AddMoneyView()
        }
    }
}```

Thank you so much guys!十分感谢大家!

It's your ZStack background.这是你的 ZStack 背景。

    var body: some View {
        NavigationView {
            VStack(alignment: .center) {
                ZStack {
                    RoundedRectangle(cornerRadius: 25)
                    .padding()
                    .foregroundColor(.white)
                    .background(Color.green)
                    .frame(width: nil, height: 250)
                    VStack {
                        Text("Verfügbar")
                            .foregroundColor(.gray)
                            .italic()
                            .font(.title2)
                        Text("Money")
                            .foregroundColor(.blue)
                            .bold()
                            .font(.largeTitle)
                        HStack {
                            Spacer()
                            VStack(alignment: .leading) {
                                Text("Einkommen")
                                    .foregroundColor(.gray)
                                    .italic()
                                HStack {
                            Label("", systemImage: "arrow.up.circle")
                                .foregroundColor(.green)
                                    Text("money").bold()
                                }
                            }
                            Spacer()
                            VStack(alignment: .trailing) {
                                Text("Ausgaben")
                                    .foregroundColor(.gray)
                                    .italic()
                                HStack {
                            Label("", systemImage: "arrow.down.circle")
                                .foregroundColor(.red)
                                    Text("money").bold()
                                }
                            }
                            Spacer()
                        }
                        .padding(5)
                    }
                }.background(Color.red)
                List {
//                    ForEach(money) { money in
//                        NavigationLink(destination: EditMoneyView(money: money)) {
//                            HStack {
//                                VStack(alignment: .leading, spacing: 6) {
//                                    Text(money.name!)
//                                        .bold()
//
//                                    Text("\(money.amount, specifier: "%.2f")") + Text("€")
//                                }
//                                Spacer()
//                                Text("\(money.date!, style: .date)")
//                                    .foregroundColor(.gray)
//                                    .italic()
//                            }
//                        }
//                    }
//                    .onDelete(perform: deleteMoney)
                }
            }
            .navigationBarTitle("Financist", displayMode: .inline)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button {
//                        showingAddView.toggle()
                        print("DEBUG: Button")
                    } label: {
                        Label("Hinzufügen", systemImage: "plus.circle")
                    }
                }
            }
            .background(.red) // added this
//            .sheet(isPresented: $showingAddView) {
//                AddMoneyView()
//            }
        }

    }

图片供参考

I think it is just default spacing, make it zero我认为这只是默认间距,将其设为零

NavigationView {
    VStack(alignment: .center, spacing: 0) {   << here !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM