SwiftUIでListを使うとデフォルトで下線部が出てます。こいつ、消したいです

結論:listRowSeparator を子Viewにつけたら消える!個別設定できる

ひとまずデフォルトはこんな感じ

灰色のViewの間に区切り線があるね。これ消します

struct test_listinsets: View {
    var body: some View {
        List{
            listItem()
                .listRowSeparator(.hidden)  ///← これをつけた
            listItem()
            listItem()
        }
        .listStyle(GroupedListStyle())
        
    }
}


struct listItem:View{
    var body: some View{
        
        Rectangle()
            .frame(maxWidth: .infinity)
            .frame(height:200)
            .foregroundColor(Color.gray)
    }
}

.listRowSeparator(.hidden) を追加したViewの下の区切り線が消えたね

隙間を埋めてくっつけたいとか、そういう話は別の設定があるので以下を参照してたぶんできる

コメント