簡體   English   中英

更改 ScrollView SwiftUI 的背景顏色

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM