[英]Change Background Color of ScrollView SwiftUI
我是開發 IOS 應用程序的新手,根據屏幕上圖像的大小,我的登錄頁面底部有多余的空白。 有人告訴我應該更改 ScrollView 的背景顏色並將視圖的背景設置為清晰。 我不確定如何更改 ScrollView 的背景顏色。 我的代碼基本上看起來像這樣,為了便於閱讀,刪除了一些內容:
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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.