Ios 更改ScrollView SwiftUI的背景色
我是开发IOS应用程序的新手,根据屏幕上图像的大小,我的登录页面底部有额外的空白。有人告诉我,我应该更改ScrollView的背景色,并将视图的背景设置为清晰。我不确定如何更改ScrollView的背景色。我的代码基本上是这样的,为了可读性,删除了一些内容:Ios 更改ScrollView SwiftUI的背景色,ios,swift,swiftui,scrollview,background-color,Ios,Swift,Swiftui,Scrollview,Background Color,我是开发IOS应用程序的新手,根据屏幕上图像的大小,我的登录页面底部有额外的空白。有人告诉我,我应该更改ScrollView的背景色,并将视图的背景设置为清晰。我不确定如何更改ScrollView的背景色。我的代码基本上是这样的,为了可读性,删除了一些内容: var body: some View { ScrollView { //if login.isLoggedIn { MainView() //} else { VSt
var body: some View {
ScrollView {
//if login.isLoggedIn {
MainView()
//} else {
VStack() {
}
.background(LinearGradient(gradient: Gradient(colors: [Color{.lightblue), Color(.blue)]), startPoint: .top, endPoint: .bottom))
.edgesIgnoringSafeArea(.all)
}
}
}
//}
有人能告诉我如何改变背景色吗?我更喜欢上面的线性渐变的背景色。如果没有,能否在UIScrollView中演示如何执行此操作?尝试将背景颜色设置移到下面一行。也可能有帮助
struct ContentView: View {
var body: some View {
ScrollView {
//if login.isLoggedIn {
MainView()
//} else {
VStack() {
}
}.background(
LinearGradient(gradient: Gradient(colors: [Color(.lightblue), Color(.blue)]), startPoint: .top, endPoint: .bottom)
).edgesIgnoringSafeArea(.all)
}
}
...
// Extension for custom colour lightBlue
extension UIColor {
static let lightBlue = UIColor(red: 0.2, green: 0.6, blue: 0.8, alpha: 1)
}
您确定您的代码运行正常吗?它似乎有很多错误,比如
Color{blue)
和CColor(blue)
.CColor是导入库中的一种类型吗?为什么在两个位置都传递blue
颜色?它应该是.blue
,除非您在代码中的其他位置定义了它,比如let blue:CGColor=.blue
。@ParthTamane是的,它运行。我只是键入了错误。蓝色是两种不同的颜色es和实际上是蓝色框/颜色框。我忘了它们的名称。我不小心试图编辑你的答案而不是我原来的帖子。np接受了你的编辑。奖金+2;)