在Swift中移除屏幕底部的模糊边界。

huangapple go评论46阅读模式
英文:

Removing blur borderline at the bottom of the screen in Swift

问题

我正在尝试删除屏幕底部的模糊边界。我尝试了.edgesIgnoringSafeArea(.all)但没有成功。我认为与堆叠相关,但我对Xcode相当新,不太确定该怎么做。

ContentView.swift

import SwiftUI

struct ContentView: View {
    @StateObject var cartManager = CartManager()
    
    var columns = [GridItem(.adaptive(minimum: 160), spacing: 20)]
    
    var body: some View {
        NavigationView {
            VStack {
                ScrollView {
                    LazyVGrid(columns: columns, spacing: 20) {
                        ForEach(productList, id: \.id) { product in
                            ProductCard(product: product)
                                .environmentObject(cartManager)
                        }
                    }
                    .padding()
                }
                //.background(Color.white.ignoresSafeArea(.all))
                //更改背景颜色
                .background(Color(UIColor(hexString: "#f0f0f0")))
                .navigationTitle(Text("Brunnings"))
                .toolbar {
                    ToolbarItem(placement: .bottomBar) {
                        HStack {
                            Navbar(image: Image("Home"), destination: EmptyView())
                            Spacer()
                            Navbar(image: Image("Location"), destination: StoreLocationView())
                            Spacer()
                            Navbar(image: Image("Profile"), destination: ProfileView())
                        }
                        .padding(8)
                        .background(Color(UIColor(hexString: "#F8F8F8")))
                        .clipShape(Capsule())
                        .padding(.horizontal)
                        .shadow(color: Color.black.opacity(0.15), radius: 8, x: 2, y: 6)
                        .frame(maxHeight: .infinity, alignment: .bottom)
                    }
                    ToolbarItem(placement: .navigationBarTrailing) {
                        NavigationLink(destination: CartView().environmentObject(cartManager)) {
                            CartButton(numberOfProducts: cartManager.products.count)
                        }
                    }
                }
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

我希望它看起来像下面这样。
在Swift中移除屏幕底部的模糊边界。

英文:

I am trying to delete the blurry borderline thats at the bottom of the screen.I have tried the .edgesIgnoringSafeArea(.all) but no luck. I assume something related to stacking but I am quite new to xcode so I am not quite sure what to do here.

ContentView.swift


struct ContentView: View {
    @StateObject var cartManager = CartManager()
    
    var columns = [GridItem(.adaptive(minimum: 160), spacing: 20)]
    
    var body: some View {
        NavigationView {
            VStack {
                ScrollView {
                    LazyVGrid(columns: columns, spacing: 20) {
                        ForEach(productList, id: \.id) { product in
                            ProductCard(product: product)
                                .environmentObject(cartManager)
                        }
                    }
                    .padding()
                }
                //.background(Color.white.ignoresSafeArea(.all))
                //Change the background color
                .background(Color(UIColor(hexString: "#f0f0f0")))
                .navigationTitle(Text("Brunnings"))
                .toolbar {
                    ToolbarItem(placement: .bottomBar) {
                        HStack {
                            Navbar(image: Image("Home"), destination: EmptyView())
                            Spacer()
                            Navbar(image: Image("Location"), destination: StoreLocationView())
                            Spacer()
                            Navbar(image: Image("Profile"), destination: ProfileView())
                        }
                        .padding(8)
                        .background(Color(UIColor(hexString: "#F8F8F8")))
                        .clipShape(Capsule())
                        .padding(.horizontal)
                        .shadow(color: Color.black.opacity(0.15), radius: 8, x: 2, y: 6)
                        .frame(maxHeight: .infinity, alignment: .bottom)
                    }
                    ToolbarItem(placement: .navigationBarTrailing) {
                        NavigationLink(destination: CartView().environmentObject(cartManager)) {
                            CartButton(numberOfProducts: cartManager.products.count)
                        }
                    }
                    
            }
            }
            
        }
        
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

在Swift中移除屏幕底部的模糊边界。

I want it to look something like this below.
在Swift中移除屏幕底部的模糊边界。

答案1

得分: 1

以下是您提供的代码的翻译部分:

这是我对使用 ZStack 创建自定义工具栏的看法。设计并不是很出色,但有助于理解发生了什么。

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationStack {
            ZStack(alignment: .bottom) {
                ScrollView {
                    LazyVStack {
                        ForEach(1...16, id: \.self) {
                            Text("\($0)")
                                .padding()
                                .frame(maxWidth: .infinity)
                                .background(Color(UIColor.systemGray6))
                        }
                    }
                }
                .navigationBarTitleDisplayMode(.inline)
                .toolbar {
                    ToolbarItem(placement: .principal) {
                        Text("Brunnings")
                    }
                    ToolbarItem(placement: .navigationBarTrailing) {
                        Image(systemName: "cart")
                    }
                }
                HStack {
                    Spacer()
                    Image(systemName: "house.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                    Spacer()
                    Image(systemName: "map.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                    Spacer()
                    Image(systemName: "person.crop.circle.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                    Spacer()
                }
                .padding()
                .background(Color.red)
                .clipShape(Capsule())
                .padding()
            }
        }
    }
}
英文:

Here's what I think about using a ZStack for a custom toolbar. The design isn't great but it helps to understand what's going on.

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationStack {
            ZStack(alignment: .bottom) {
                ScrollView {
                    LazyVStack {
                        ForEach(1...16, id: \.self) {
                            Text("\($0)")
                                .padding()
                                .frame(maxWidth: .infinity)
                                .background(Color(UIColor.systemGray6))
                        }
                    }
                }
                .navigationBarTitleDisplayMode(.inline)
                .toolbar {
                    ToolbarItem(placement: .principal) {
                        Text("Brunnings")
                    }
                    ToolbarItem(placement: .navigationBarTrailing) {
                        Image(systemName: "cart")
                    }
                }
                HStack {
                    Spacer()
                    Image(systemName: "house.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                    Spacer()
                    Image(systemName: "map.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                    Spacer()
                    Image(systemName: "person.crop.circle.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                    Spacer()
                }
                .padding()
                .background(Color.red)
                .clipShape(Capsule())
                .padding()
            }
        }
    }
}

huangapple
  • 本文由 发表于 2023年5月26日 00:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76334627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定