英文:
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()
}
}
英文:
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()
}
}
答案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()
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论