どうも、ちょげ(@chogetarou)です。
リストの背景色を透明にする方法を紹介します。
方法

Listの背景色を透明にするには、UITablViewとlistRowBackgroundColorを使います。
まず、UITablView.appearance().backgroundColorに「.clear」を代入します。
UITableView.appearance().backgroundColor = .clear
そして、リストの要素にlistRowBackgroundColorを付与し、引数に「Color.clear」を指定します。
List {
ItemView()
.listRowBackground(Color.clear)
}
これでListの背景が透明になります。
使用例
以下は、使用例です。

struct ContentView: View {
init () {
UITableView.appearance().backgroundColor = .clear
}
var body: some View {
ZStack {
Rectangle()
.foregroundColor(.green.opacity(0.2))
List {
ForEach (1..<6, id: \.self) { index in
Text("\(index)")
.listRowBackground(Color.clear)
}
}
}
}
}
コメント