どうも、ちょげ(@chogetarou)です。
リストのセクションヘッダーの高さを変える方法を紹介します。
方法

Listのセクションヘッダーの高さを変えるには、envrionment修飾子を使います。
まず、Listもしくはそれより上の階層のビューに「environment」を付与します。
そして、environmentの第1引数に「\.defaultMinListHeaderHeight」、第2引数にセクションの高さを指定します。
List {
//Some Item
}
.environment(\.defaultMinListHeaderHeight, /*高さ*/)
environmentの「\.defaultMinListHeaderHeight」を使うことで、Listのセクションの高さを変えることができます。
使用例
以下は、使用例です。

struct ContentView: View {
var body: some View {
VStack {
List {
Section(
header: Text("Section 1")
) {
ForEach (1..<6, id: \.self) { index in
Text("\(index)")
}
}
Section(
header: Text("Section 2")
) {
ForEach (6..<11, id: \.self) { index in
Text("\(index)")
}
}
}
.listStyle(GroupedListStyle())
}
.environment(\.defaultMinListHeaderHeight, 50)
}
}
コメント