Shi*_*utt 3 background ios swift swiftui swiftui-navigationlink
我正在尝试更改此视图的背景颜色,但无法做到这一点。我尝试将背景(Color.green)放在HStack、VSTack甚至ZStack上,但它不起作用,不确定我是否放在正确的位置。默认情况下,它采用手机或模拟器颜色,即白色,但我想应用自定义背景颜色我的 Xcode 版本是 11.5
struct HomePageView: View {
@State var size = UIScreen.main.bounds.width / 1.6
var body: some View {
GeometryReader{_ in
VStack {
HStack {
ZStack{
// main home page components here....
NavigationView{
VStack {
AssignmentDaysView()
}.background(Color.lairBackgroundGray)
.frame(width: 100, height: 100, alignment: .top)
.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()
}
Spacer()
}.animation(.spring()).background(Color.lairBackgroundGray)
Spacer()
}
}
}
}
}
struct HomePageView_Previews: PreviewProvider {
static var previews: some View {
HomePageView()
}
}
Run Code Online (Sandbox Code Playgroud)
在你的NavigationView你有一个VStack. 相反,您可以使用 aZStack并在VStack.
请尝试以下操作:
NavigationView {
ZStack {
Color.green // <- or any other Color/Gradient/View you want
.edgesIgnoringSafeArea(.all) // <- optionally, if you want to cover the whole screen
VStack {
Text("assignments")
}
.background(Color.gray)
.frame(width: 100, height: 100, alignment: .top)
}
}
Run Code Online (Sandbox Code Playgroud)
注意:您使用了许多包装在GeometryReader您不使用的堆栈中。考虑通过删除不必要的堆栈来简化视图。另外,如果您使用,您可能不需要 GeometryReader UIScreen.main.bounds(但是,GeometryReader在 SwiftUI 中是首选)。
尝试删除一些层:您可以从删除顶部的层开始:GeometryReader, VStack, HStack...
| 归档时间: |
|
| 查看次数: |
8502 次 |
| 最近记录: |