[SwfitUI] List 안전영역까지 배경색 채우기

jonghwan·2022년 10월 25일
0

SwiftUI

목록 보기
1/2
post-thumbnail

안전 영역까지 배경색을 채우기 위해 안전 영역 외부의 색상 배경을 변경하는 방법으로 ZStack 안에

Color.black.ignoresSafeArea()

Color.black.edgesIgnoringSafeArea(.all) modifier를 사용해도 배경이 바뀌지 않았다..

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            // Color.black.ignoresSafeArea()
            // Color.black.edgesIgnoringSafeArea(.all)
            List {
                ForEach(stockData) { list in
                    StockListRow(stock: list)
                }
                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
            }
            .listStyle(.plain)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

해결 방법은 !

.scrollContentBackground(.hidden) modifier를 사용해서 List의 표준 배경을 숨긴다.

.background(.black) 새로운 배경색을 설정한다.

import SwiftUI

struct ContentView: View {
    var body: some View {
//        ZStack {
//            Color.black.ignoresSafeArea()
//            Color.black.edgesIgnoringSafeArea(.all)
//
            List {
                ForEach(stockData) { list in
                    StockListRow(stock: list)
                }
                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
            }
            .listStyle(.plain)
            .background(.black)
            .scrollContentBackground(.hidden)

0개의 댓글