【发布时间】:2020-10-24 11:48:41
【问题描述】:
我正在尝试在 SwiftUI 中构建应用程序并面临 1 个挑战(Xcode 版本 11.5)-
-
在 iPhone 11 模拟器上运行应用程序时,背景色不会出现在整个屏幕上,屏幕底部仍然是白色,但是在 iPhone 8 模拟器上运行时,它工作正常。不确定是模拟器问题还是代码问题。我尝试添加 Spacer,更改 VStack,HStack 但它不起作用。
struct HomePageView: View { @State var size = UIScreen.main.bounds.width / 1.6 var body: some View { GeometryReader{geometry in VStack { HStack { ZStack{ NavigationView{ ZStack { ScrollView(.vertical, showsIndicators: false) { VStack { View1() }.frame( maxWidth: .infinity) } .navigationBarItems(leading: Button(action: { self.size = 10 }, label: { Image("menu") .resizable() .frame(width: 30, height: 30) }).foregroundColor(.appHeadingColor), trailing: Button(action: { print("profile is pressed") }) { HStack { NavigationLink(destination: ProfileView()) { LinearGradient.lairHorizontalDark .frame(width: 30, height: 30) .mask( Image(systemName: "person.crop.circle") .resizable() .scaledToFit() ) } } } ).navigationBarTitle("Home", displayMode: .inline) } } HStack{ menu(size: self.$size) .cornerRadius(20) .padding(.leading, -self.size) .offset(x: -self.size) Spacer().background(Color.lairBackgroundGray) } //Spacer() }.animation(.spring()).background(Color.lairBackgroundGray) //Spacer() }.padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top) .padding(.bottom, UIApplication.shared.windows.first?.safeAreaInsets.bottom) }.frame(height: geometry.size.height).background(Color.lairBackgroundGray) }//.background(Color.lairBackgroundGray.edgesIgnoringSafeArea(.all)) } }下面是我的另一个视图,它基本上是作为主视图的一部分在屏幕上绘制的。请原谅我在这里放了这么多代码,但想确定是不是因为 View1 -
结构视图1:视图{ @State 变量索引 = 0 var body: 一些视图{ // 滚动视图 { GeometryReader { 几何输入 堆栈{ 堆栈{ 堆栈{ ZStack{ 圆圈() .trim(从:0,到:1) .stroke(Color.lairDarkGray.opacity(0.09), style: StrokeStyle(lineWidth: 34, lineCap: .round)) .frame(宽: 80, 高: 80)
Circle() .trim(from: 0, to: 0.5) .stroke(LinearGradient(gradient: Gradient(colors: [.buttonGradientStartColor, .buttonGradientEndColor]), startPoint: UnitPoint(x: -0.2, y: 0.5), endPoint: .bottomTrailing), style: StrokeStyle(lineWidth: 34, lineCap: .round)) .frame(width: 80 , height: 80) .rotationEffect(.init(degrees: -90)) Text("15") .font(.system(size:30)) .fontWeight(.bold) }.padding() Text("Day(s)") .foregroundColor(Color.black.opacity(0.8)) }.frame(height: 100) VStack(alignment: .leading, spacing: 12){ HStack { Image("1") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 170, height: 170) } .background(Color.lairBackgroundGray) //.padding(.bottom, 5) } .padding(.leading, 20) Spacer(minLength: 0) } .padding(.horizontal, 20) }//.frame(height: geometry.size.height) .background(Color.lairBackgroundGray.edgesIgnoringSafeArea(.all)) } //} } }[![enter image description here][1]][1]
【问题讨论】:
标签: ios xcode background swiftui ios-simulator